From: Shaun Morrow on
I am working on code that implements a delegate design pattern, this makes
use of the call_user_func_array function.

I am having trouble with this particular line in PHP 5.3
return call_user_func_array(array($delegate, $methodName), $parameters);

$delegate is an object, and not simply the class name in a string.

This works in versions of PHP lower than 5.3, but it seems as though the
behaviour of this function was changed in 5.3, requiring you to pass the
class name, meaning that the method will always be called statically.

So my question is, is there any way that I can emulate the functionality of
call_user_func_array that was present in PHP < 5.3?

I would prefer not to use eval, but would like to retain the ability to call
methods within objects dynamically.

Sorry if I am not making myself clear, advice and input would be
appreciated.
From: Nathan Nobbe on
On Mon, Jun 28, 2010 at 12:39 PM, Shaun Morrow <morrow.shaun(a)gmail.com>wrote:

> I am working on code that implements a delegate design pattern, this makes
> use of the call_user_func_array function.
>
> I am having trouble with this particular line in PHP 5.3
> return call_user_func_array(array($delegate, $methodName), $parameters);
>
> $delegate is an object, and not simply the class name in a string.
>
> This works in versions of PHP lower than 5.3, but it seems as though the
> behaviour of this function was changed in 5.3, requiring you to pass the
> class name, meaning that the method will always be called statically.
>
> So my question is, is there any way that I can emulate the functionality of
> call_user_func_array that was present in PHP < 5.3?
>
> I would prefer not to use eval, but would like to retain the ability to
> call
> methods within objects dynamically.
>
> Sorry if I am not making myself clear, advice and input would be
> appreciated.
>


i never saw anything about a change to call_user_func_array as you describe
in php5.3 moreover a quick test shows its working as expected, namely when
the first argument of the callback array is an object, not a string naming a
class.

<?php

echo phpversion() . PHP_EOL;
class A {
function b() {
var_dump(__METHOD__);
}
}

$a = new A();
?>

5.3.0
string(4) "A::b"

-nathan
From: Nathan Nobbe on
On Mon, Jun 28, 2010 at 12:51 PM, Nathan Nobbe <quickshiftin(a)gmail.com>wrote:

>
>
> On Mon, Jun 28, 2010 at 12:39 PM, Shaun Morrow <morrow.shaun(a)gmail.com>wrote:
>
>> I am working on code that implements a delegate design pattern, this makes
>> use of the call_user_func_array function.
>>
>> I am having trouble with this particular line in PHP 5.3
>> return call_user_func_array(array($delegate, $methodName), $parameters);
>>
>> $delegate is an object, and not simply the class name in a string.
>>
>> This works in versions of PHP lower than 5.3, but it seems as though the
>> behaviour of this function was changed in 5.3, requiring you to pass the
>> class name, meaning that the method will always be called statically.
>>
>> So my question is, is there any way that I can emulate the functionality
>> of
>> call_user_func_array that was present in PHP < 5.3?
>>
>> I would prefer not to use eval, but would like to retain the ability to
>> call
>> methods within objects dynamically.
>>
>> Sorry if I am not making myself clear, advice and input would be
>> appreciated.
>>
>
>
> i never saw anything about a change to call_user_func_array as you describe
> in php5.3 moreover a quick test shows its working as expected, namely when
> the first argument of the callback array is an object, not a string naming a
> class.
>
> <?php
>
> echo phpversion() . PHP_EOL;
> class A {
> function b() {
> var_dump(__METHOD__);
> }
> }
>
> $a = new A();
> ?>
>
> 5.3.0
> string(4) "A::b"
>
> -nathan
>

omg - i chopped off the critical part of the code segment :O

here it is in full:

<?php

echo phpversion() . PHP_EOL;
class A {
function b() {
var_dump(__METHOD__);
}
}

$a = new A();

call_user_func_array(array($a, 'b'), array());
?>

-nathan