php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20676 serialize(): Reinitialization of a reference
Submitted: 2002-11-27 09:22 UTC Modified: 2004-04-08 20:06 UTC
Votes:7
Avg. Score:4.6 ± 1.0
Reproduced:4 of 5 (80.0%)
Same Version:1 (25.0%)
Same OS:2 (50.0%)
From: alex_boyer at hotmail dot com Assigned:
Status: Wont fix Package: Class/Object related
PHP Version: 4CVS OS: *
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2002-11-27 09:22 UTC] alex_boyer at hotmail dot com
I try to keep reference on all instances of a class. Even, unserialized one.

<?php
class A {
    var $x=1;
    
    function __wakeup(){
        $GLOBALS['ref'] =& $this;
    }
}


function set(){
    //Serialize information
    $a =& new A();
    $a->x=2;
    $data = serialize($a);
    
    //Unserialize
    $b =& unserialize($data); // i try without '&'
    $result= $b === $GLOBALS['ref']; // $result == true;    
    echo "VALUE IN SET: {$b->x} \n"; // Echo 2
}

set();
echo "VALUE OUT SET: {$GLOBALS['ref']->x}\n"; //echo nothing, $GLOBALS['ref'] is now NULL !
?>

I have read all docs, my eyes burns me but i really cannot understand. I look in database too. 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-27 09:32 UTC] alex_boyer at hotmail dot com
i thought that PHP count references on data before destroys it. This is not the case. This is why $GLOBALS['ref'] is null isn't it ?
 [2002-12-09 06:57 UTC] andi@php.net
This shouldn't really part of the scripting engine bugs but addressed to the authors of serialize() and unserialize(). Re-classifying.
 [2004-04-08 20:06 UTC] sniper@php.net
"Fixed" in PHP 5 (where you don't even need to play around with references..)

 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Aug 29 15:01:52 2017 UTC