Re: Allow Iterator to be used with current, next, reset, key functions

From: Date: Sun, 30 Oct 2016 23:32:50 +0000
Subject: Re: Allow Iterator to be used with current, next, reset, key functions
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  Groups: php.internals 
Request: Send a blank email to internals+get-96669@lists.php.net to get a copy of this message
On 10/31/2016 12:25 AM, Yasuo Ohgaki wrote: > It depends. Defining specific functions for a task could be bad design > also. We do design basic functions with flags usually, too. > I know that we have lots of them but they almost always end up in hard to read and understand I-can-do-everything functions and their implementation is also cluttered with branching. On 10/31/2016 12:25 AM, Yasuo Ohgaki wrote: > That said, dedicated functions for getting first/last key/value sounds > good to me. > > A agree. That's the reason why I state return value is problem. However, > > if (empty($arr)) { > // Do something > } else { > $first = array_first($arr); > } > > shouldn't be difficult. > > We should raise error for nonsense usage. Programmers have to check > empty()/isset() all the time anyway. > I am an assert programmer, hence, I have no problem with an error in such a case if others are fine with it. @Rowan absolutely right, hence, if really needed: ``` function array_shift_key(array $array); function array_pop_key(array $array); ``` -- Richard "Fleshgrinder" Fussenegger

« previous php.internals (#96669) next »