On 9/12/09 12:31 AM, "Paul M Foster" <pa...@quillandmouse.com> wrote:

> On Fri, Sep 11, 2009 at 07:31:01PM -0400, Tom Worster wrote:
> 
>> if i have an expression that evaluates to an object, the return value from a
>> function, say, and i only want the value of one of the objects properties,
>> is there a tidy way to get it without setting another variable?
>> 
>> to illustrate, here's something that doesn't work, but it would be
>> convenient if it did:
>> 
>> $o = array( (object) array('a'=>1), (object) array('a'=>2) );
>> 
>> if ( end($o)->a > 1 ) {  // can't use -> like this!
>> ...
>> }
>> 
> 
> You should use print_r() or var_dump() to investigate what happens when
> you try to cast an array into an object. I myself don't know what would
> happen. Also, what's allowed and what effects are produced could depend
> heavily on the version of PHP you're running. Version 4 != 5 != 5.3 in
> this respect.

i did that long ago when i was looking for php's object literal syntax. i
didn't find one. we discussed it here more recently and consensus appeared
to be that casting an array was the most convenient workaround.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to