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 #177554 is a reply to message #177553] Mon, 09 April 2012 18:37 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 4/9/2012 2:04 PM, Thomas Mlynarczyk wrote:
> Jerry Stuckle schrieb:
>
>> The __clone() method is a form of a constructor. But wakeup() isn't.
>
> Neither is. Cloning simply copies a previously constructed object while
> __wakeup() changes the state of a previously constructed object.
>

Yes, __clone() is a form of a constructor. It creates a new object from
an existing object of the same type. In C++ this would be known as the
copy constructor, for instance. In Java it is the clone() method. Both
are considered constructors.

Also, when the object is serialized, it no longer is an object. It has
state but no behavior - the data are there but not the methods.

So when it is deserialized, a new object is created and by definition a
constructor must be called.

>> And if you argue that wakeup() is a form of a constructor,
>
> I don't and never did.
>
>> then you have to argue that sleep() is a form of a destructor - in
>> which case it would be invalid to call the destructor after calling
>> sleep().
>
> Serialization creates a kind of "frozen" copy of an object. The original
> object continues to exist and its destructor is called as expected.
> Later, the "frozen" copy is "warmed up" and can pretend to be the
> original object, but it is not the same object. The __sleep() and
> __wakeup() methods simply assist with the freezing and warming up and
> have nothing to do with the copying.
>

No, all serialization does is save the contents of the object. It is no
longer an object. The call to the original object's destructor is
correct. And, as you mentioned, when it is deserialized, it is no
longer the same object - it is a new one, so a constructor must be called.

> To sum it up: A new object can be created by either constructing it
> (which calls __construct()) or by copying an existing object (via clone
> or via serialization) and this happens without calling __construct() on
> the copy since the object is already constructed. And this explains why
> there may be more __destruct() calls than __construct() calls in a script.
>
> Greetings,
> Thomas
>

In object oriented programming, a new object can ONLY be created by
calling a constructor. As noted above, different languages have
different terms for them. But a constructor MUST be called according to
OO principles.

--
==================
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: Sun Dec 01 01:29:05 GMT 2024

Total time taken to generate the page: 0.04196 seconds