note 83517 added to language.oop.magic-functions
| From: | matthes at leuffen dot de | Date: | Thu, 29 May 2008 16:10:41 +0000 |
| Subject: | note 83517 added to language.oop.magic-functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139984@lists.php.net to get a copy of this message | ||
To serialize private or protected properties, you need to add the classname to the name of the
property (otherwise serialize() will return empty properties):
<?php
// Works:
class SerializeMe {
private $myPrivateProperty;
public function __sleep () {
return array ("\0".__CLASS__."\0"."myPrivateProperty");
}
}
?>
It looks stupid: Without any __sleep() method private Properties are serialized as well as protected
and public. But if you add a __sleep() method, they won't.
This may help you saving some hours of googleing ;-)
----
Server IP: 212.124.37.9
Probable Submitter: 217.86.142.15
----
Manual Page -- http://www.php.net/manual/en/language.oop.magic-functions.php
Edit -- https://master.php.net/note/edit/83517
Del: integrated -- https://master.php.net/note/delete/83517/integrated
Del: useless -- https://master.php.net/note/delete/83517/useless
Del: bad code -- https://master.php.net/note/delete/83517/bad+code
Del: spam -- https://master.php.net/note/delete/83517/spam
Del: non-english -- https://master.php.net/note/delete/83517/non-english
Del: in docs -- https://master.php.net/note/delete/83517/in+docs
Del: other reasons-- https://master.php.net/note/delete/83517
Reject -- https://master.php.net/note/reject/83517
Search -- https://master.php.net/manage/user-notes.php