You are here: Re: call_user_func_array vs $myfunction( &$params ) « PHP Programming Language « IT news, forums, messages
Re: call_user_func_array vs $myfunction( &$params )

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация