php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50775 Array does not serialize properly
Submitted: 2010-01-16 01:27 UTC Modified: 2010-01-24 01:00 UTC
From: tolkad dot freenode at gmail dot com Assigned:
Status: No Feedback Package: Arrays related
PHP Version: 5.2.12 OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-01-16 01:27 UTC] 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
    }
  }
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-16 03:45 UTC] rasmus@php.net
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 21:56 UTC] tolkad dot freenode at gmail dot com
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.
 [2010-01-24 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 20 14:03:39 2021 UTC