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 #177558 is a reply to message #177554] Mon, 09 April 2012 20:50 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:

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

Just to avoid confusion: When a new object is created, PHP must do some
work under the hood like allocating memory etc. and this of course is
"construction" work which is always done and in that sense a constructor
is indeed always called.

But after that, there is (or is not) the call to __construct(). And now
that I think of it, the name __construct() is actually not quite
correct, since the actual construction of the object is already done at
that point. What __construct() really does is perform some
initialization (in Python, the corresponding method is indeed called
__init__()).

And this initialization is not needed (or might even prove harmful) when
the object is copied rather than created from scratch, because in that
case the initialization was already done on the original object and the
copy was thus created from an already initialized object and it will
"inherit" the initialized state. Instead, there are __clone() and
__wakeup() which replace __construct() and can do different
initialization tasks depending on how the object was created.

Therefore I must correct my earlier remark about neither __clone() nor
__wakeup() being constructors: __construct(), __clone() and __wakeup()
are all "of the same kind" -- performing initialization of an object
depending on how it was created.

On the other hand, __sleep() is not a destructor, because nothing is
destroyed when it is called. Note that __sleep() is supposed to return
an array, contrary to __destruct(). So, while the names __sleep() and
__wakeup() suggest a correspondence like __destruct() and __construct(),
this is not the case, since __sleep() is called on the original object,
while __wakeup() is called on the resurrected copy, so they're not
called on the same object.

Anyway, I must thank you for making me think more thoroughly about this.

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:54:05 GMT 2024

Total time taken to generate the page: 0.04110 seconds