Re: call_user_func_array how to use on object php >= 5.3

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

 



On Mon, Jun 28, 2010 at 12:39 PM, Shaun Morrow <morrow.shaun@xxxxxxxxx>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

[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