> Either I know that the array is not empty, or I do not care because NULL will 
> be ignored correctly.
> In the second case, with a tuple I’m stuck because if I do:
>
> if (array_first(some_function())[1] > 3) {
>   // do something
> }
>
> If array_first returns NULL this will trigger a PHP error. So I have to add 
> more code to handle this special case while I do not need any with 
> array_first_value.

This is true. For completeness the fix is very mild:

    if (([$_, $value] = array_first(some_function()) && $value > 3) {
        // do something
    }

I still think this is better. Forcing you to handle the error case is
not a bad thing.

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

Reply via email to