Re: Closures in PHP

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

 



On Jan 16, 2008 1:58 AM, Larry Garfield <larry@xxxxxxxxxxxxxxxx> 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

[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