Re: Variadic is_*() functions
| From: | Levi Morrison | Date: | Mon, 11 Feb 2019 16:34:49 +0000 |
| Subject: | Re: Variadic is_*() functions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-104345@lists.php.net to get a copy of this message | ||
>> I recognize that there is one downside, which is that lazy evaluation
>> is lost, but generally don't see it to be an issue in these specific
>> cases.
>>
> Lazy evaluation doesn't have to be lost if the all_of and any_of functions are written
> correctly. all_of will return false as soon as one of them fails, and any_of will return true as
> soon as one of them passes.
>
> Unless you are talking about cases like this:
> if(is_numeric(reallyFastFunc($foo)) || is_numeric(reallySlowFunc($bar)))
> In that case, you might be able to short circuit the evaluation of reallySlowFunc($bar), which
> wouldn't be the case with
> if(any_of('is_numeric',reallyFastFunc($foo),reallySlowFunc($bar))){}
Yes, this is what I was referring to. As previously stated, I don't
think it's likely to be an issue. If it is, then as you stated the
normal boolean logic can be used in such places.
-----
In other words, nothing needs to be done in PHP itself. Just write or
use someone else's
all_of, any_of, none_of, etc,
functions.