Re: Re: $arr = array('Hello', 'world'); $arr();
| From: | Rune Kaagaard | Date: | Thu, 14 Jul 2011 21:03:27 +0000 |
| Subject: | Re: Re: $arr = array('Hello', 'world'); $arr(); | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53964@lists.php.net to get a copy of this message | ||
Will this work:
array('foo', 'bar')('arg1', 'arg2')
?
On Wed, Jun 8, 2011 at 3:48 PM, Christian Kaps
<christian.kaps@mohiva.com> wrote:
> On Wed, 8 Jun 2011 15:39:59 +0200, Jordi Boggiano wrote:
>>
>> On Wed, Jun 8, 2011 at 2:46 PM, Felipe Pena <felipensp@gmail.com> wrote:
>>>
>>> class foo {
>>> public function __construct() {
>>> $this->bar = function () { return 1; };
>>> // $this->bar(); // error
>>> $x = $this->bar;
>>> $x(); // ok
>>>
>>> $this->bar = array($this, 'baz');
>>> // $this->bar(); // error
>>> $x = $this->bar;
>>> $x(); // ok
>>> }
>>> public function baz() {
>>> echo 'baz';
>>> }
>>> }
>>
>> What he meant was passing an existing method as a callback if you
>> don't invoke it, i.e. passing "$this->bar" instead of array($this,
>> "bar"). I don't know how hard it'd be to achieve, but it sounds pretty
>> awesome to me.
>>
>> Cheers
>
> Yep, just what I meant.
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>