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 #177618 is a reply to message #177592] Tue, 10 April 2012 21:34 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 4/10/2012 12:15 PM, Thomas Mlynarczyk wrote:
> 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().
>

I know you did. And I said __sleep() is called after the constructor.
It can also be called after __wakeup(), i.e. if an unserialized object
is serialized again.

> 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.)
>

OK, now - one of the members of the object is a reference to a database
connection object. How are you going to set that in your __wakeup() call?

Yes, I know what the PHP manual says. But it's also pretty obvious that
those who wrote the manual are the same ones who created the language.

Thanks, I'll go with recognized OO experts when discussing how OO works
- not the PHP folks.

> <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
>

My statement stands for a database object with the unserialize() method.

If either followed the OO rules for constructing an object, this would
not be a problem.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[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: Fri Nov 22 14:20:56 GMT 2024

Total time taken to generate the page: 0.04886 seconds