php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #16073 Cannot unserialize() a string serialized with serialize()
Submitted: 2002-03-14 10:20 UTC Modified: 2011-01-01 00:34 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:0 of 0 (0.0%)
From: ahristov at icygen dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.0CVS-2002-03-14 OS: RH 7.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ahristov at icygen dot com
New email:
PHP Version: OS:

 

 [2002-03-14 10:20 UTC] ahristov at icygen dot com
Not sure if this is a bug but serialize() cannot work with arrays that holds elements which points to the array itself

<?php
        $b=array(1,2,4);
  $b[]=&$b;
        $str=serialize($b);
        var_dump($b);
        var_dump($str);
        $c=unserialize($str);
        var_dump($c);
?>
The ouput is:
array(4) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(4)
  [3]=>
  *RECURSION*
}
string(64) "a:4:{i:0;i:1;i:1;i:2;i:2;i:4;i:3;a:4:{i:0;i:1;i:1;i:2;i:2;i:4;}}"
bool(false)

If 
$b[]=&$b;
removed the output is:
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(4)
}
string(30) "a:3:{i:0;i:1;i:1;i:2;i:2;i:4;}"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(4)
}
That's ok.
Serialize() have either to check against recursion or encode somehow the recursion in the serialized(great BC impact).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-01 00:34 UTC] jani@php.net
-Status: Open +Status: Bogus -Package: Feature/Change Request +Package: *General Issues
 [2011-01-01 00:34 UTC] jani@php.net
AFAIK, this was some bug that got fixed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 06:01:32 2025 UTC