Hi niel,

On 15.06.2018 at 17:37 niel wrote:
What is the behaviour if the array does not exist? From the current RFC it appears it would return null? Wouldn't it be better to return false for this situation?


Thanks for the comment. Why do you think false would be a better return value?

Currently if the given value isn't an array or no parameter is given a warning will be thrown and null will be returned. In my opinion null exists to show the absence of a defined value. If one of the proposed functions is called with a variable which isn't an array or an empty array (or even a call with no parameter) there is neither a first nor a last key and thus null is the value which is returned.
Compare the tests for the error cases:
https://github.com/php/php-src/pull/3256/files#diff-e00a584724b997f38e851e15f1e20c39

This behavior is also implemented in existing functions like eg. array_pop():
https://github.com/php/php-src/blob/master/ext/standard/tests/array/array_pop_errors.phpt

Enno


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

Reply via email to