Re: Language constructs and callability
> array_filter([…], 'is_null');
Doesn't work -- is_null
would return TRUE leaving a result of [NULL]
after the array_filter operation. That's the diametric opposite of what my
example code looks to do.
On Fri, Jul 19, 2013 at 1:07 PM, Peter Cowburn <[email protected]>wrote:
>
>
>
> On 19 July 2013 17:36, Daniel Lowrey <[email protected]> wrote:
>
>> I have a simple question about the callability of language constructs and
>> whether or not that's something that might change in the future. Consider:
>>
>> var_dump(is_callable('echo')); // bool(false)
>> var_dump(call_user_func('echo', 'foo')); // E_WARNING
>> echo('foo'); // foo
>>
>> var_dump(is_callable('isset')); // bool(false)
>> var_dump(isset(1)); // E_ERROR
>>
>> Obviously this behavior arises because tokens like echo
and isset
>> are
>> language constructs and not functions. I can see some potential benefits
>> for working around this. For example, say I want to filter only the NULL
>> elements from an array but keep the other "falsy" values. Recognizing
>> isset
as callable would allow me to do this:
>>
>> var_dump(array_filter([0, FALSE, NULL], 'isset')); // [0, FALSE]
>>
>
> array_filter([…], 'is_null');
>
>
>>
>> Of course, this limitation is trivial to work around with a userland
>> callback to check for the explicit NULL equivalency, but it would be nice
>> to avoid the hassle. So my question is ...
>>
>> How deeply ingrained into the engine is this behavior? Is there any chance
>> of language constructs ever passing the tests for callability or is that
>> just a pipe dream that's not worth the implementation effort?
>>
>
>
Thread (22 messages)