On 8 June 2011 09:47, Alexey Shein <con...@gmail.com> wrote:
> 2011/6/8 Hannes Magnusson <hannes.magnus...@gmail.com>:
>> We have the situation in the docs that parameters declared as arrays
>> do not follow the typehinting rules, but parameters as class names do.
>> Re-using the callback from the docs could get confusing when
>> extensions start to typehint on it, but not the core..
>>
>> I think there is a subtle difference between a callback, and a callable.
>> In javascript for example, callback is something that is executed on
>> certain events "onsuccess" is the typical example.
>> There is nothing that says the callable parameter gets executed as a
>> part of an event, and I think the default usecase would be to execute
>> it right away (f.e. filtering data).
>>
>> I think I would prefer callable, but I could live with either.
>>
>
> Wikipedia defines callback as "a reference to executable code, or a
> piece of executable code, that is passed as an argument to other
> code". So there's no "event" meaning put by default, it's just very
> often seen callback's usage in javascript.
> I just like "callback" term more :)

An interesting issue here.

Closures, classes with an __invoke method and strings containing
existing function names all pass is_callable() and can be called using
().

But, array('class', 'method') also passes is_callable, but isn't a callback.

http://pastebin.com/Yb5nJ8DB

outputs ...

object is callable
Invoked : Wed, 08 Jun 2011 11:24:09 +0100
object is callable
Closure : Wed, 08 Jun 2011 11:24:09 +0100
string is callable
Wed, 08 Jun 2011 11:24:09 +0100
array is callable
Handling Array via call_user_func
Func array : Wed, 08 Jun 2011 11:24:09 +0100

So, callable and callbacks are 2 different things.

Callable
1 - closures.
2 - classes with an __invoke method.
3 - strings to an existing function.
4 - array('class', 'method')

Callbacks
Only 1, 2 and 3 from the above list.

If you try to use $funcarray(), you get the following fatal error ...

Fatal error: Function name must be a string



-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to