Re: [RFC][Under Discussion] Add functions array_key_first() and array_key_last()

From: Date: Mon, 18 Jun 2018 00:34:01 +0000
Subject: Re: [RFC][Under Discussion] Add functions array_key_first() and array_key_last()
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-102289@lists.php.net to get a copy of this message
Hi niel, Am 18.06.2018 um 01:59 schrieb niel:
However my main concern that a non-array variable or a non-existent value, are an error and need to be handled appropriately, has not changed. IMO, a notice/warning does little to nothing in helping the programmer determine the problem and track down the cause. Which leaves one having to wrap these functions in 'if (is_array($var) && !empty($var)) {...}' to prevent the possibility.
The current implementation is eqivalent to the other array_* functions as shown in the previous mail and can be checked in https://github.com/php/php-src/pull/3256/commits/ec2332be93272d202a2a5cef841c266f77f64b08#diff-e00a584724b997f38e851e15f1e20c39 I can comprehend your doubts about the return value but currently I can't imagine a solution which would suite the case better than null especially if we think about extending the scope to array_value_(first|last). Do you/anyone have an idea how we can provide better information towards the programmer to determine the issue? Enno

« previous php.internals (#102289) next »