Re: Language constructs and callability

From: Date: Fri, 19 Jul 2013 17:16:55 +0000
Subject: Re: Language constructs and callability
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
> Oh yeah, I see your point about is_null but not why it makes any more
sense to allow language constructs there.

Yeah I don't know if it even does. I'm not even really sure if there's a
good example use case for it besides the array_filter/isset combo. My
question was really only exploratory in nature.


On Fri, Jul 19, 2013 at 1:12 PM, Peter Cowburn <[email protected]>
 wrote:

> Oh yeah, I see your point about is_null but not why it makes any more
> sense to allow language constructs there.
>


On Fri, Jul 19, 2013 at 1:11 PM, Jelle Zijlstra <[email protected]>wrote:

>
>
>
> 2013/7/19 Peter Cowburn <[email protected]>
>
>> 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');
>>
>> That would do the opposite of what you want.
>
>>
>> >
>> > 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)

« previous php.internals (#68211) next »