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 #177573 is a reply to message #177568] Tue, 10 April 2012 11:28 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:

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

Really? That would be very strange indeed.

[minutes later]
I just tested it and it is indeed as you state. Thanks for pointing that
out -- is this documented?

> 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.

I don't quite follow you here. Why did they have no choice? I don't see
why they (c|sh)ould not call the constructor before setting the data.
After all, that would be the only logical and sensible thing to do. If
you would do this "manually", you would do it like this:

foreach ( $rows as $row ):
$item = new MyClass( 'foo', 'bar' );
foreach ( $row as $name => $value ):
$item->$name = $value;
endforeach;
$result[] = $item;
endforeach;

And I guess it would be impossible to do it the other way round (first
setting data, then calling constructor). The setting of the data can be
controlled using the magic __set() method, so there's no need for
__pdoconstruct(), if I understand you correctly.

A more intelligent approach may have been to define an interface which
any "result row" class must implement and which defines a method like
setData( $rowAsArray ). Or maybe even better: make use of the existing
__set_state() magic method.

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: Thu Nov 28 06:54:33 GMT 2024

Total time taken to generate the page: 0.04396 seconds