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 #177575 is a reply to message #177568] Tue, 10 April 2012 11:58 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 4/10/2012 4:05 AM, M. Strobel wrote:
> Am 10.04.2012 02:17, schrieb Jerry Stuckle:
>> On 4/9/2012 4:50 PM, Thomas Mlynarczyk wrote:
>>
>>> 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.
>>>
>>
>> Initialization is NEVER harmful if it is done properly. That's the whole purpose of
>> initialization!. wakeup() is NOT a constructor - any more than sleep() is a destructor.
>
> 'if done properly' fits everywhere and is just too true to be useful.
>
> In PHP the constructor is called on an object without state (data). So you would
> normally in the constructor just write out our data, like setting a counter to zero
> or a date to the current time. This would be harmful to do on a 'not new' object.
>

But you are creating an object without state. When the object state is
serialized, by definition it is no longer an object because it has no
behavior.

You need to understand what an object is according to Object Oriented
principles. An object has both state and behavior - it has properties
and methods which act on those properties. The latter is not possible
in a serialized object.

And yes, you call the constructor when creating ANY object, even if the
object is being created from existing data.

Your understanding of object oriented principles shows you have never
read much about it nor have you use a true OO language.

> Now PDO comes in. When getting a query result as object your constructor is called
> *after* the properties are set.
>

And exactly how is that?

> I found it quite annoying to have an exception from the rule. But thinking more about
> it I found out they had a choice of either calling __construct() after setting the
> data, or to define another magic method like __pdoconstruct() to give the programmer
> a chance to adapt the init process to the data.
>

Another problem - you should NEVER call the constructor. True OO
languages do that for you as part of creating a new object. And you
never have to call the parent constructor, either.

PHP is sadly lacking as an OO language, that's for sure.

> Bottom line is: you just have to know your programming language very well, and test
> everything thoroughly. Knowledge of OO principles help a lot, but are often too
> general to be operational (like for example the "Open Close Principle").
>
> /Str.

Bottom line is - PHP's OO is sadly lacking, as it is in so many areas.

--
==================
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: Fri Nov 22 14:11:37 GMT 2024

Total time taken to generate the page: 0.04125 seconds