On 02/06/2021 00:34, Mike Schinkel wrote:
But from all this I do agree with you that just returning an array
would likely be acceptable.
-----
This would not be a great solution for really large arrays, but then we can't
eliminate the need for a developer to have a reasonable level of knowledge,
right? So:
$unshifted = $array->unshift($new_element);
$shifted = $array->shift();
But, we could also possibly use better names for these:
$right_shifted = $array->shift_right(...$new_element(s));
$left_shifted = $array->shift_left([element_count]);
IMO for unshift() it'd be fine to return a new array, but when
processing a list of things in a FIFO pattern I often used array_shift()
to get the first "job" out of the array. If $array->shift() returns a
new array then how do I access the first item?
I mean sure one can call reset first to get it, but I find this isn't
great ergonomics compared to the existing.
Best,
Jordi
--
Jordi Boggiano
@seldaek - https://seld.be
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php