Re: Re:[VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last()

From: Date: Wed, 11 Jul 2018 13:37:56 +0000
Subject: Re: Re:[VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last()
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-102751@lists.php.net to get a copy of this message
> 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.

« previous php.internals (#102751) next »