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 #177611 is a reply to message #177606] Tue, 10 April 2012 21:11 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 2:10 PM, Thomas Mlynarczyk wrote:
> M. Strobel schrieb:
>
>> In your example above the problem is if you need to do more init work
>> on the data you
>> need an extra method call. With the implemented solution you just have
>> to know that
>> the constructor is called after setting the vars, and you can detect
>> it, testing the
>> unique key or so, but need not do so if you don't care.
>
> Hm, yes, but it still feels wrong to me that the constructor call is not
> the very first thing happening to the object.
>

I agree that it "feels wrong", but is perfectly valid. There are other
examples - for instance in Java and C++, the vase class constructor is
called before the derived class constructor.

>> Are you aware of the fact that __set() is not called for defined
>> variables?
>
> Yes, it's not called for defined /public/ variables. But you rarely have
> public variables in your classes.
>
>> The rationale (or use case) of __set_state() is a mystery to me.
>
> Well, it's used by var_export() when exporting objects. For example,
>
> $a = (object) array( 'foo' => 'bar' );
>
> will be exported as
>
> stdClass::__set_state(array( 'foo' => 'bar', ))
>
> even though PHP should know very well that stdClass has no such static
> method. Consequently, writing the output of var_export() to a file and
> then re-including it, will fail, thus defeating the whole purpose of
> var_export(). Test code:
>
> $a = (object) array( 'foo' => 'bar' );
> $s = var_export( $a, true );
> var_dump( $a, $s );
> $b = eval( "return $s;" );
> var_dump( $b );
>
> But __set_state() seems to be some sort of "factory method" which is
> called as a static method on a class, passing an array with "state
> information" and the method is supposed to create an object, set its
> state using the passed array and return the new object. And that would
> be exactly what PDO needs to set the data of the row object: no need to
> define an array with extra constructor arguments -- just tell PDO the
> class name and make sure the class has a __set_state() method defined.
> But alas, it's not what PDO does.
>
> Greetings,
> Thomas
>

Possibly for future use? Most of PDO was written before __set_state()
was added, so maybe newer versions will use it.

--
==================
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: Tue Nov 26 06:08:03 GMT 2024

Total time taken to generate the page: 0.08626 seconds