Hi John,

Thanks for submitting the RFC. It just has one piece of something that I
feel needs a bit of refinement.

The balance of the $key and the $val is out of sync, with one param being
by-val and one by-ref.

You could simplify the function to remove the &$val altogether, since the
function name is about getting the key. Less is more here.

I know you pointed out examples of other unusual functions, but we must
live with those things historically for BC reasons. Given the opportunity
to get it right I'd like to propose removal of &$val so the function does
what its name says.

Thus it would look like this:
$val = $array[array_key_last($array)];

Many thanks,
Paul


On Fri, Jan 1, 2016 at 9:51 PM, John Bafford <jbaff...@zort.net> wrote:

>
> > On Jan 1, 2016, at 16:38, Bishop Bettini <bis...@php.net> wrote:
> >
> > On Fri, Jan 1, 2016 at 3:44 PM, John Bafford <jbaff...@zort.net> wrote:
> > Happy New Year, everyone!
> >
> > I’d like to present the first new PHP RFC for this year, a proposal to
> add functions to easily get the first, last, or an arbitrary key (and
> value) by index from an array, taking advantage of PHP’s property that
> arrays are ordered maps.
> >
> > Thanks for submitting this RFC!  I am +1, with one quibble: obtaining
> the value by reference seems non-sequitur to the function itself and PHP in
> general.  IOW, this seems more PHPesque to me:
> >
> > // get the next to last value
> > $key = array_key_index($arr, -2);
> > $val = $arr[$key];
> >
> > Sincerely,
> > bishop
>
> While relatively rare for PHP, these aren't the only functions that have
> an optional second return value by reference. (preg_match, preg_replace,
> str_replace, among others.)
>
> I agree that that’s a bit unusual in terms of PHP, but, if you actually
> need both the key and the value, this way you can do it in one call, rather
> than having to access the array and pull the value out of it separately.
> The C code already has a reference to the hashtable bucket, so returning
> the value if it’s needed is trivial.
>
> -John
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Reply via email to