From:             mytrash at seznam dot cz
Operating system: Windows XP
PHP version:      5.0.1
PHP Bug Type:     Zend Engine 2 problem
Bug description:  Serialization does not work when I use private/protected members and 
__sleep()

Description:
------------
Hello.

I use PHP session. When I use private or protected members in my class and
don't use magic method __sleep(), PHP serialization will serialize all
members and their values into PHP session correctly.
But when I use the same class and implement magic method __sleep(), PHP
serialization will serialize correctly ONLY public members. Private and
protected members (that I want serialize - I specified them in array
returned from __sleep() function) have NULL value.
In my example's result is string from session file generated by PHP.

T.Zkoumalek

Reproduce code:
---------------
class Test
{
    private   $a = "Variable a";
    protected $b = "Variable b";
    public    $c = "Variable c";
    public    $d = "This need not be saved.";


    // Save only $a, $b, $c.
    function __sleep()
    {
        return Array( "a", "b", "c" );
    }
}

session_start();
$_SESSION[ "test" ] = new Test();

Expected result:
----------------
test|O:4:"Test":3:{s:7:" Test a";s:10:"Variable a";s:4:" *
b";s:10:"Variable b";s:1:"c";s:10:"Variable c";}

Actual result:
--------------
test|O:4:"Test":3:{s:1:"a";N;s:1:"b";N;s:1:"c";s:10:"Variable c";}

-- 
Edit bug report at http://bugs.php.net/?id=29754&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29754&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29754&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29754&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29754&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29754&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29754&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29754&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29754&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29754&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29754&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29754&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29754&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29754&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29754&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29754&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29754&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29754&r=float

Reply via email to