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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 28, 2008 at 4:22 PM, Jim Lucas <lists@xxxxxxxxx> 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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux