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 #177608 is a reply to message #177606] Tue, 10 April 2012 18:23 Go to previous messageGo to previous message
M. Strobel is currently offline  M. Strobel
Messages: 386
Registered: December 2011
Karma:
Senior Member
Am 10.04.2012 20:10, schrieb Thomas Mlynarczyk:
> 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.
>
>> 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.

Still a mystery, why should I want to do var_export()? And your code gives a fatal error.

<shrug> but it's late here, getting dark

/Str.
[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: Mon Nov 25 21:09:03 GMT 2024

Total time taken to generate the page: 0.04340 seconds