Re: Closures in PHP
| From: | Nathan Nobbe | Date: | Wed, 16 Jan 2008 14:43:35 +0000 |
| Subject: | Re: Closures in PHP | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-267386@lists.php.net to get a copy of this message | ||
On Jan 16, 2008 1:58 AM, Larry Garfield <larry@garfieldtech.com> wrote:
> On Tuesday 15 January 2008, Nathan Nobbe wrote:
>
> > when i said a function would have to be loaded into the interpreter to
> > avoid a runtime error
> > upon invocation, i didnt mention that its best to programatically verify
> it
> > can be called before
> > letting the runtime error occur (of course you can let that happen if
> you
> > prefer :)), to avoid it.
> > anywho, i prefer the variable function construct more than
> > call_user_func(), simply
> > because it feels a bit more natural to me, but semantically, they are
> the
> > same, they just have
> > a different syntax is all. i suppose call_user_func() is a bit more
> clear
> > and might help some
> > people when drifting through the code of others.
> > cool contrived example, btw ;)
> >
> > -nathan
>
> Not true, actually. $function() is considerably faster than
> call_user_func()
> or call_user_func_array(). call_user_func_array(), however, lets you pass
> in
> an arbitrary number of parameters while the other two do not.
not quite.
speed has nothing to do w/ semantics, and if you read the doc on
call_user_func()
you can pass in a variable number of parameters (which is what i said in my
later post).
the difference is call_user_func_array() takes an array w/ the parameters to
pass to the
function it invokes and call_user_func() accepts the standard format for a
variable number
of parameters.
eg. (from php.net)
mixed *call_user_func* ( callback $function [, mixed $parameter [, mixed
$... ]] )
-nathan