|
Posted by Rik on 08/01/07 12:32
On Wed, 01 Aug 2007 11:04:23 +0200, gosha bine <stereofrog@gmail.com> =
wrote:
> On 01.08.2007 10:11 FFMG wrote:
>
>> What is the difference between
>> // -- $params =3D array( $stuff);
>> $myFn =3D 'foo';
>> $myFn($params)
>> // -- And // -- $params =3D array( $stuff);
>> $myFn =3D 'foo';
>> call_user_func_array( $myFn, $params );
>> // -- Wont they both achieve the same result?
>>
>
> call_user_func_array is useful when the number of parameters to a call=
ed =
> function is variable or unknown, for example:
>
> function nice_dump() {
> $params =3D func_get_args();
> echo "<pre>";
> call_user_func_array('var_dump', $params);
> echo "</pre>";
> }
>
> nice_dump(1, 2, 3);
Indeed, it's not really function name that's interesting in this =
particular example, it's the parameters that particular piece of code =
doesn't have to worry about.
Then again, one of it's major advantages is it also supports callbacks, =
so =
you can easily give a class function or object method to it. Your code =
would be rather complex to get that otherwise...
-- =
Rik Wasmus
Navigation:
[Reply to this message]
|