And.. here is my original motivation for
#1853112: Replacement for Krumo?

I had a strange case where a dpm($node) would change the way that Drupal works.
In one case, the node was rendered by an advanced_forum template. In another case it was rendered by a theme node.tpl.php.
Ouch!

After hours of pain, I can now present sth reproducible:

function testme() {
  $x = new stdClass;
  $x->foo = array('bar');
  $is_reference = _check_ref($x, 'foo');
  dpm($is_reference ? 'yes' : 'no');
  // Let's do it again, to show that the side effect is not caused by repeated _check_ref().
  $is_reference = _check_ref($x, 'foo');
  dpm($is_reference ? 'yes' : 'no');
  dpm($x);
  $is_reference = _check_ref($x, 'foo');
  dpm($is_reference ? 'yes' : 'no');
}

function _check_ref($obj, $key) {
  $orig = $obj->$key;
  $c = clone $obj;
  $c->$key = 'tmp';
  $is_reference = ($obj->$key === $c->$key);
  $c->$key = $orig;
  return $is_reference;
}

Result:
no
no
(krumo output)
yes

Pretty bad, isn't it?

Comments

donquixote’s picture

That's on PHP 5.3.5

donquixote’s picture

Title: Crazy reference bug in Krumo » Krumo side effect: Object vars become references

better title

donquixote’s picture

And, just saying, krumong()->dpm() does not have this effect.

EDIT:
I only tested this for objects so far, not for arrays.

donquixote’s picture

Update:
- krumo does have this side effect on objects, but not on arrays.
- krumong does not have this side effect, neither for arrays nor for objects.

I suppose there is some PHP 4.x logic in krumo causing this mess.

salvis’s picture

We've seen unexplained odd behavior before, after calls to krumo, and this may well be the cause.

It's rare that it makes a difference, but when it does, it's really nasty!

Thank you for the analysis and for your work in #1853112: Replacement for Krumo?!

ttkaminski’s picture

Wow, this is a major bug. I just started using dpm() recently and ran into this problem right away. I created a module that displays all forms so that I can easily alter and style them.

function MODULE_form_alter(&$form, &$form_state, $form_id) {
  dpm($form);
}

However, because of this bug, the node fields will become corrupted in the template_preprocess_node() resulting in a corrupt $node object for subsequent preprocess_node hooks.

ttkaminski’s picture

I installed krumong and the integration patch for devel #1853112: Replacement for Krumo? and I no longer have any corruption issues with dpm(). Thanks @donquixote!

donquixote’s picture

Here is an interesting background article.
Seems to be a problem in PHP itself. So we should be careful not to blame the authors of Krumo.
http://float-middle.blogspot.de/2010/02/php-references-to-array-elements...

cmonnow’s picture

Issue summary: View changes

If it doesn't already, this bug should probably have a higher profile. It seems somewhat serious when one of the primary methods of debugging could cause such unexpected results.

frob’s picture

It is quite possible that this nasty bug is related #2366797: Running dpm on global $user object logs the user in as user 1.

willzyx’s picture

Status: Active » Closed (outdated)

Closing for lack of activity. Feel free to reopen if the issue still exists