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 #185094 is a reply to message #185090] Wed, 26 February 2014 02:10 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 2/25/2014 6:22 PM, Adam Harvey wrote:
> On Tue, 25 Feb 2014 17:01:52 -0500, Jerry Stuckle wrote:
>> On 2/25/2014 4:55 PM, Christoph Michael Becker wrote:
>>> I firmly believe that it wouldn't make sense to call a (user-defined)
>>> constructor when unserializing or cloning an object. A constructor
>>> usually serves to initialize an object -- what already had happened in
>>> both cases.
>>>
>>>
>> It makes perfect sense. Not everything is necessarily valid in the new
>> object. For instance, a logging object may require opening the log
>> file. There are many instances where a resource is no longer available
>> and needs to be recreated.
>
> Indeed, which is why PHP provides the Serializable interface (and, for BC
> reasons, also __sleep and __wakeup) to allow those sorts of
> reinitialisation tasks.
>
> I agree with Christoph: since the object is already instantiated, it
> doesn't logically make sense to call the constructor once again.
>

But the object is NOT instantiated. It was at one time, then destroyed.
When the new script starts, there is no object in existence.

>>> Jerry Stuckle wrote:
>>>> I know of no other OO language which would allow this.
>>>
>>> Others may.
>>>
>>>
>> None that I know of. Please name one.
>
> Python's pickle operates the same way:
> http://docs.python.org/2/library/pickle.html#object.__getinitargs__
>
> Providing a way to instantiate objects without calling the constructor
> does have valid uses (mostly for testing), which is why PHP 5.4 and later
> versions also provide a way to do so via reflection (avoiding the
> unserialize() hack):
> http://php.net/reflectionclass.newinstancewithoutconstructor
>
> Adam
>

Not knowing Python, I can't say. But if it is a true object, then they
are also violating OO principles.

OO demands creation of a new object requires a constructor call.
Period. If you think otherwise, I suggest you learn more about how OO
is supposed to work. PHP is not a good example.



--
==================
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: Thu Nov 28 03:41:38 GMT 2024

Total time taken to generate the page: 0.04493 seconds