FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » out of sheer curiosity...
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: out of sheer curiosity... [message #177592 is a reply to message #177579] Tue, 10 April 2012 16:15 Go to previous messageGo to previous message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma:
Senior Member
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". You can have a
class defining both methods and still have only one of the two methods
called during the life time of the instance:

$foo = new Foo;
echo serialize( $foo );
// end of script
// __sleep() is called, but never __wakeup()

$string = '<manually created serialized representation of object>';
$foo = unserialize( $string );
// end of script
// __wakeup() is called, but never __sleep()

> And what you're saying is that the destructor (__sleep()) is called
> after a constructor (__construct(), __clone() or __wakeup()).

I said the exact opposite: __sleep() is called *before* the
corresponding __wakeup().

And look what the PHP manual has to say (emphasis mine):

<http://de2.php.net/manual/en/language.oop5.magic.php#object.wakeup>:
"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.)

<http://de2.php.net/manual/en/class.serializable.php>
"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()."

(Clearly, unserialize() replaces __wakeup(), and if unserialize() acts
as a constructor, then so does __wakeup() which it replaces.)

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: 5.4 windows installer.
Next Topic: Does PHP5 treat $_SERVER['PHP_AUTH_USER']) differently?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 28 08:45:05 GMT 2024

Total time taken to generate the page: 0.04685 seconds