Re: Re: $arr = array('Hello', 'world'); $arr();
Hi,
2011/6/8 Christian Kaps <[email protected]>
> Hi,
>
>
> Hi all,
>> Reading our bug tracker I noticed a good feature request [1] from 2009
>> which
>> points to an interesting feature that I think makes sense for us, since we
>> are now working with $f() using objects and strings, and the
>> array('class',
>> 'method') is an old known for call_user_func()-like functions.
>>
>> So, I wrote a patch [2] that allow such behavior to be consistent with
>> arrays. See some examples:
>>
>> class Hello {
>> public function world($x) {
>> echo "Hello, $x\n"; return $this;
>> }
>> }
>>
>> $f = array('Hello','world');
>> var_dump($f('you'));
>>
>> $f = array(new Hello, 'foo');
>> $f();
>>
>> All such calls match with the call_user_func() behavior related to magic
>> methods, static & non-static methods.
>>
>> The array to be a valid callback should be a 2-element array, and it must
>> be
>> for the first element object/string and for the second string only. (just
>> like our zend_is_callable() check and opcodes related to init call)
>>
>> Any thoughts?
>>
>>
>
> what happens if I use this code.
>
> class Foo {
>
> public $bar;
>
> public function __construct() {
>
> $this->bar = array($this, 'baz');
> $this->bar();
> }
>
> public function bar() {
> echo 'bar';
> }
>
> public function baz() {
> echo 'baz';
> }
> }
>
> new Foo();
>
> What is the output of this snippet?
>
> Are there the same rules as for closures?
>
> Christian
>
>
Yes, the same rules.
--
Regards,
Felipe Pena
Thread (9 messages)