ID:               50775
 Comment by:       tolkad dot freenode at gmail dot com
 Reported By:      tolkad dot freenode at gmail dot com
 Status:           Feedback
 Bug Type:         Arrays related
 Operating System: All
 PHP Version:      5.2.12
 New Comment:

I am re-assigning $x to a new recursive array created by unserializing
that string. For some reason PHP doesn't treat this like a recursive
array when re-serializing it and when var_dumping it.


Previous Comments:
------------------------------------------------------------------------

[2010-01-16 03:45:55] [email protected]

Can you explain why you think the last var_dump() should show 
recursion?  Looking at it, I don't see it since you are re-assigning $x

there and you lose the recursive reference in doing so.

------------------------------------------------------------------------

[2010-01-16 01:27:55] tolkad dot freenode at gmail dot com

Description:
------------
When certain strings are unserialized they do not reserialize properly.

Reproduce code:
---------------
<?php
$x = array();
$x[] = &$x;

var_dump($x);
$z = serialize($x);
echo $z . "\n";
var_dump(unserialize($z));

echo "\n\n\n";

$x = unserialize("a:1:{i:0;R:1;}");
var_dump($x);
$z = serialize($x);
echo $z . "\n\n";
var_dump(unserialize($z));


Expected result:
----------------
array(1) {
  [0]=>
  &array(1) {
    [0]=>
    &array(1) {
      [0]=>
      *RECURSION*
    }
  }
}
a:1:{i:0;a:1:{i:0;R:2;}}
array(1) {
  [0]=>
  &array(1) {
    [0]=>
    &array(1) {
      [0]=>
      *RECURSION*
    }
  }
}



array(1) {
  [0]=>
  &array(1) {
    [0]=>
    &array(1) {
      [0]=>
      *RECURSION*
    }
  }
}
a:1:{i:0;R:1;}

array(1) {
  [0]=>
  &array(1) {
    [0]=>
    &array(1) {
      [0]=>
      *RECURSION*
    }
  }
}


Actual result:
--------------
array(1) {
  [0]=>
  &array(1) {
    [0]=>
    &array(1) {
      [0]=>
      *RECURSION*
    }
  }
}
a:1:{i:0;a:1:{i:0;R:2;}}
array(1) {
  [0]=>
  &array(1) {
    [0]=>
    &array(1) {
      [0]=>
      *RECURSION*
    }
  }
}



array(1) {
  [0]=>
  array(1) {
    [0]=>
    array(1) {
      [0]=>
      *RECURSION*
    }
  }
}
a:1:{i:0;a:1:{i:0;a:1:{i:0;N;}}}

array(1) {
  [0]=>
  array(1) {
    [0]=>
    array(1) {
      [0]=>
      NULL
    }
  }
}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50775&edit=1

Reply via email to