Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder4.news.weretis.net!news.musoftware.de!wum.musoftware.de!fu-berlin.de!uni-berlin.de!not-for-mail From: "M. Strobel" Newsgroups: comp.lang.php Subject: Re: out of sheer curiosity... Date: Tue, 10 Apr 2012 19:09:15 +0200 Lines: 41 Message-ID: <9uj7psF94nU1@mid.uni-berlin.de> References: <17777949.TfjZNtg3zH@PointedEars.de> <9tij5fFmi8U1@mid.uni-berlin.de> <4f74567c$0$6887$e4fe514c@news2.news.xs4all.nl> <4f746ff9$0$6918$e4fe514c@news2.news.xs4all.nl> <9uebvuFt0pU1@mid.uni-berlin.de> <9ueidtFagfU1@mid.uni-berlin.de> <9ufofaFvj5U1@mid.uni-berlin.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de xJsHj1g13TAcdoultxVCfQIBQRbnzQQ8wxpxXoUUDo9FVe/Fk= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; de; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20 In-Reply-To: Xref: csiph.com comp.lang.php:5430 Am 10.04.2012 18:15, schrieb Thomas Mlynarczyk: > Jerry Stuckle schrieb: > >> If you are considering __wakeup() to be a constructor, then __sleep(), being >> exactly the opposite, would be a destructor. (why do you think they are called >> "sleep" and "wakeup" if the designers didn't consider them to be opposites?). > > They are opposites with respect to the process of serialization and may be thought of > as "to-do-before" and "to-do-after". And __sleep() is not the exact opposite of > __wakeup() -- the object is still awake after __sleep() has been called and will > continue to "work". Good point, the object is still awake, that's why you get a destruct call at the end of script. > And look what the PHP manual has to say (emphasis mine): > > : > "Conversely, unserialize() checks for the presence of a function with the magic name > __wakeup(). If present, this function can *reconstruct* any resources that the object > may have." > > (So __wakeup() is meant to "reconstruct" something, thus clearly acting as a > constructor.) > > > "Classes that implement this interface no longer support __sleep() and __wakeup(). > The method serialize is called whenever an instance needs to be serialized. This does > not invoke __destruct() or has any other side effect unless programmed inside the > method. When the data is unserialized the class is known and the appropriate > unserialize() method is called as a *constructor* instead of calling __construct()." > And note the Note: It is not possible for __sleep() to return names of private properties in parent classes. (...) Instead you may use the Serializable interface. But it is more work. /Str.