Re: echo returnArray()['a']; // workaround

From: Date: Fri, 29 Feb 2008 00:03:19 +0000
Subject: Re: echo returnArray()['a']; // workaround
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-270667@lists.php.net to get a copy of this message
On Thu, Feb 28, 2008 at 4:22 PM, Jim Lucas <lists@cmsws.com> wrote: > So, I guess my question would be, why not take it one level deeper. > > <?php > include('ArrayClass.php'); > > function sillyFunc() { > return ArrayClass::create(array('a' => 1, 'b' => 2, > 'c' => 3, 'd' => > 4)); > } > > echo sillyFunc()->a . PHP_EOL; > ?> the idea is that you get something that can be used repeatedly. in your example you are creating the array that is supplied to the ArrayClass::create() method, whereas in mine it is supplied by something else. of course you could create a global function that wraps the ArrayClass::create() method, and in that case it might make sense to leave the constructor public and just wrap the instantiation of the ArrayClass class. but thats why i created the static method in the first place, that and the issue we observed a while back about not being able to invoke a method on an object in the same statement that instantiates it. -nathan

« previous php.general (#270667) next »