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 #177606 is a reply to message #177600] Tue, 10 April 2012 18:10 Go to previous messageGo to previous message
Thomas Mlynarczyk is currently offline  Thomas Mlynarczyk
Messages: 131
Registered: September 2010
Karma:
Senior Member
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.

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)
[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 20:09:34 GMT 2024

Total time taken to generate the page: 0.05561 seconds