Re: [PHP] Re: Strange PHP5 message
Hi, Jason, Thanks a lot for suggestion. Does it mean that I have tried to serialize some object (like adodb db object)? How I can eliminate this? I really cannot find where this object or whatever else is going to be serailized. The problematic line of code just serialized an array. On Mar 16, 2005, at 18:30, Jason Barnett wrote: Andrei Verovski wrote: ... Notice: serialize() [function.serialize]: __sleep should return an array only containing the names of instance-variables to serialize. in ANVphpApp.php on line 840 Anyone knows what is the problem? Exactly what the notice says ;) basically __sleep is used so that you can prevent certain properties (file pointers, db connections, objects, etc.) from being serialized. ?php session_start(); error_reporting(E_ALL); class Dummy { public$s1 = 'I am a test string'; protected $s2 = 'I am the protected string'; private $_s3 = 'I am the private string'; var $a1 = array('testing', 1, 2, 3); static$i1 = 0; function __sleep() { $i = self::$i1++; echo Oops, I forgot everything! $i\n; return array(); } } class hasMemory extends Dummy { private $_fp = NULL; function __construct() { $this-_fp = fopen('/path/to/some/file', 'r'); } function __sleep() { $props_to_save = array('s1', 's2', 'a1'); echo I know about the following properties:\n; print_r($props_to_save); return $props_to_save; } } $_SESSION['obj1']= new Dummy(); $_SESSION['obj2']= new hasMemory(); $_SESSION['string'] = '123abcdefg!'; $_SESSION['integer'] = 1; $_SESSION['float'] = .1234; $_SESSION['double'] = .1234567890123456; $_SESSION['bool']= TRUE; foreach ($_SESSION as $key = $value) { echo $key: ; var_dump(serialize($value)); } ? -- Teach a man to fish... NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-generalw=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php LAZY | http://mycroft.mozdev.org/download.html? name=PHPsubmitform=Find+search+plugins * * Best Regards --- Andrei Verovski * * Personal Home Page * http://snow.prohosting.com/guru4mac/ * Mac, Linux, DTP, Development, IT WEB Site *
Re: [PHP] Re: Strange PHP5 message
Andrei Verovski wrote: Hi, Jason, Thanks a lot for suggestion. Does it mean that I have tried to serialize some object (like adodb db object)? How I can eliminate this? I really cannot find where this object or whatever else is going to be serailized. The problematic line of code just serialized an array. ... Yes, you tried to serialize some object. But rather than *not* serializing the object, what you really want to do is to fix your __sleep function. Serializing objects is A Good Thing. (tm) I don't know what your class is, but you need __sleep to return an array of class properties. Certainly you can look at the last code example that I provided and figure out how to do that. Or at least I hope that you can ;) -- Teach a man to fish... NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-generalw=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php LAZY | http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins signature.asc Description: OpenPGP digital signature
[PHP] Re: Strange PHP5 message
Andrei Verovski wrote: ... Notice: serialize() [function.serialize]: __sleep should return an array only containing the names of instance-variables to serialize. in ANVphpApp.php on line 840 Anyone knows what is the problem? Exactly what the notice says ;) basically __sleep is used so that you can prevent certain properties (file pointers, db connections, objects, etc.) from being serialized. ?php session_start(); error_reporting(E_ALL); class Dummy { public$s1 = 'I am a test string'; protected $s2 = 'I am the protected string'; private $_s3 = 'I am the private string'; var $a1 = array('testing', 1, 2, 3); static$i1 = 0; function __sleep() { $i = self::$i1++; echo Oops, I forgot everything! $i\n; return array(); } } class hasMemory extends Dummy { private $_fp = NULL; function __construct() { $this-_fp = fopen('/path/to/some/file', 'r'); } function __sleep() { $props_to_save = array('s1', 's2', 'a1'); echo I know about the following properties:\n; print_r($props_to_save); return $props_to_save; } } $_SESSION['obj1']= new Dummy(); $_SESSION['obj2']= new hasMemory(); $_SESSION['string'] = '123abcdefg!'; $_SESSION['integer'] = 1; $_SESSION['float'] = .1234; $_SESSION['double'] = .1234567890123456; $_SESSION['bool']= TRUE; foreach ($_SESSION as $key = $value) { echo $key: ; var_dump(serialize($value)); } ? -- Teach a man to fish... NEW? | http://www.catb.org/~esr/faqs/smart-questions.html STFA | http://marc.theaimsgroup.com/?l=php-generalw=2 STFM | http://php.net/manual/en/index.php STFW | http://www.google.com/search?q=php LAZY | http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins signature.asc Description: OpenPGP digital signature