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 #185097 is a reply to message #185096] Wed, 26 February 2014 13:44 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 2/26/2014 7:50 AM, Richard Damon wrote:
> On 2/25/14, 4:32 PM, Jerry Stuckle wrote:
>> On 2/25/2014 4:19 PM, Christoph Michael Becker wrote:
>>> Jerry Stuckle wrote:
>>>
>>>> On 2/25/2014 2:19 PM, Christoph Michael Becker wrote:
>>>> > Jerry Stuckle wrote:
>>>> >
>>>> >> I have my own problems with PHP - for instance, it is entirely
>>>> >> possible
>>>> >> to create an object without calling a constructor - a violation of OO
>>>> >> principles. But I work around it.
>>>> >
>>>> > How is it possible to create an object without its constructor (if
>>>> > defined) being called?
>>>> >
>>>>
>>>> Load the object from the $_SESSION. The constructor will not be called.
>>>>
>>>> However, the constructor is called when the original object was created,
>>>> and the destructor called when the original object goes out of scope.
>>>> The destructor is also called when the object loaded from the $_SESSION
>>>> goes out of scope.
>>>>
>>>> The result is one constructor call and two destructor calls. A
>>>> violation of OO principles.
>>>
>>> Um, I'm not sure whether this is a violation of OOP principles. Storing
>>> an object in the session requires serialization of the object, what is
>>> somewhat comparable to cloning an object. So actually, you're not
>>> working with the *same* object.
>>>
>>> Anyway, you can work around these issues by using the magic methods
>>> __sleep() and __wakeup(), as you probably know. :)
>>>
>>
>> Yes, it is a violation. When the script starts, the object is
>> serialized in the $_SESSION. But it does not exist in the script.
>> Creating it requires a constructor call. OO principles require exactly
>> one constructor call and one destructor call for every object created.
>> Note these may be explicit or implicit, and the functions may be noops,
>> but the calls must still be made. That is not the case here; you get
>> one constructor call and two destructor calls.
>>
>> I know of no other OO language which would allow this.
>>
>
> 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.

--
==================
Remove the "x" from my email address
Jerry Stuckle
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
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: Sun Nov 24 01:02:22 GMT 2024

Total time taken to generate the page: 0.03894 seconds