NYCPHP Meetup

NYPHP.org

[nycphp-talk] Access an element of a method that returns an ar ray

Scott Mattocks crisscott at netzero.com
Wed Jul 21 07:54:05 EDT 2004


Joe Crawford wrote:

> i dont see this working in 4 or 5 reason being is you have to have the
> method return the array before you can actually access the elemnets so
> $obj->method()[3] will not work you must assign it to a variable before
> you can access it.  

PHP 4 doesn't know what to do with this syntax but one of the changes in 
PHP 5 is to let you use the return value of a function without assigning 
it first.  If your function/method returns an object you can call 
methods of that object without assigning it to a variable first.
Ex: $obj->getOtherObj()->method();

Scott Mattocks



More information about the talk mailing list