|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-08-24 17:21 UTC] sfox@php.net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 07:00:01 2025 UTC |
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";}