php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27350 Incorrect unserialization after __sleep()
Submitted: 2004-02-22 10:57 UTC Modified: 2004-08-30 19:22 UTC
Votes:4
Avg. Score:4.8 ± 0.4
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: davojan at mail dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5CVS-2004-03-15 OS: *
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: davojan at mail dot ru
New email:
PHP Version: OS:

 

 [2004-02-22 10:57 UTC] davojan at mail dot ru
Description:
------------
When unserializing after __sleep(), private and protected fields are duplicated with the public ones with the same name.
Note, that in php5.0.0b2 the example works fine. I think it's because of "foreach", which:
- in php5b4: gives the plane names of fields;
- in php5b2: there was a string with additional information about scope ("*", for example) and with '\0' delimiters.

Reproduce code:
---------------
<?
class foo {
	public    $x = 1;
	protected $y = 2;
	private   $z = 3;
	function __sleep()
	{
		foreach ($this as $Key => $Value) {
			$Result[] = $Key;
		}
		return $Result;
	}
}
	session_start();
	$_SESSION['foo'] = new foo();
	print_r ($_SESSION['foo']);
	session_write_close();
	session_start();
	print_r ($_SESSION['foo']);
?>

Expected result:
----------------
foo Object
(
    [x] => 1
    [y:protected] => 2
    [z:private] => 3
)
foo Object
(
    [x] => 1
    [y:protected] => 2
    [z:private] => 3
)

Actual result:
--------------
foo Object
(
    [x] => 1
    [y:protected] => 2
    [z:private] => 3
)
foo Object
(
    [x] => 1
    [y:protected] => 2
    [z:private] => 3
    [y] => 
    [z] => 
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-02-22 19:33 UTC] sniper@php.net
This is not session related but serialize/unserialize problem.
Here's better test script:

<?php

class foo 
{
        public    $x = 1;
        protected $y = 2;
        private   $z = 3;

        function __sleep ()
        {
                foreach ($this as $Key => $Value) {
                        $Result[] = $Key;
                }
                return $Result;
        }

}

$foo = new foo();
$bar = unserialize(serialize($foo));

print_r($foo);
print_r($bar);

?>

Output is the same as in the initial report.

 [2004-08-30 19:22 UTC] curt@php.net
Duplicate of #26737 http://bugs.php.net/26737
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Dec 06 11:00:02 2025 UTC