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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 13:01:30 2024 UTC