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

Home » Imported messages » comp.lang.php » Operator precedence
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Object constructors/destructors [message #185147 is a reply to message #185142] Sun, 02 March 2014 19:28 Go to previous messageGo to previous message
Richard Damon is currently offline  Richard Damon
Messages: 58
Registered: August 2011
Karma:
Member
On 3/1/14, 2:22 PM, Jerry Stuckle wrote:
> On 3/1/2014 12:56 PM, Richard Damon wrote:
>> On 2/27/14, 8:25 AM, Jerry Stuckle wrote:
>>> On 2/26/2014 11:49 PM, Richard Damon wrote:
>>>> On 2/26/14, 8:44 AM, Jerry Stuckle wrote:
>>>> > On 2/26/2014 7:50 AM, Richard Damon wrote:
>>>> >>
>>>> >> An the "name" of the Deserializing constructor in PHP is __wakeup().
>>>> >>
>>>> >> You also do NOT get two destructor calls on the same object, the
>>>> >> deserializing created a new object.
>>>> >>
>>>> >
>>>> > __wakeup() is not a constructor - and does not do the same thing.
>>>> >
>>>>
>>>> What makes it NOT a constructor? IT seems to be exactly the thing that
>>>> does what you say must be done to make the new object via
>>>> unserialization.
>>>>
>>>
>>> If you want to consider __wakeup() to be a constructor, then you must
>>> consider __sleep() to be a destructor. In that case, PHP is also wrong
>>> because if an object is serialized, it will call both __sleep() and the
>>> destructor. This would be two calls to destructors for the same object.
>>>
>>
>> WHY does __sleep() need to be a destructor?
>>
>> __sleep() is a function to control how an object is serialized, and the
>> object, as you seem to know, still exists, so no destructor should
>> happen at this point, in fact, if you look at it, __sleep() has not
>> expected to have any effect on the current object, its purpose is to
>> make sure that __wakeup() will get all the data it needs, and allow the
>> removal of data that it won't need.
>>
>
> If you are going to claim __wakeup() is a constructor, then you have to
> agree that it's opposite (__sleep()) is a destructor. Otherwise you are
> being inconsistent.
>
> You can't just make up rules as you see fit!
>

Then why are you claiming that something that isn't a desturctor must be
one.

Serialization, creates an external representation for an object, that is
what __sleep() is part of. This does NOT inherently involve the
destruction of the object (at least at that point).

Deserialization, on the other hand, creates an object from an external
representation. so it will involve the construction of a new object (you
can do "in-place" deserialization in some languages, where you first
create a dummy object, and then fill it in with the external data, but
this is normally a clumsy way to define it).

Note that the object oriented paradigm does have asymmetry in it. A
given type will tend to have multiple constructors, for the different
ways that an object might come into existence. There is usually only one
destructor. In PHP, one of these constructors is called __construct()
which is the general purpose constructor. (unlike in other statically
type languages, we can only define one of these). PHP also lets us
define a piece of the deserialing constructor with __wakeup() (PHP does
some of the heavy lifting here in parsing the serialized data and
setting up the object, __wakeup() is just required to do any final
needed operations after the values have been set.)
[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
Previous Topic: Correlating curl resources to some other object.
Next Topic: Experienced Web designer required
Goto Forum:
  

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

Current Time: Wed Nov 27 18:12:08 GMT 2024

Total time taken to generate the page: 0.03784 seconds