On Wed, Jul 11, 2018 at 10:16 AM Levi Morrison <le...@php.net> wrote: > > On Wed, Jul 11, 2018 at 9:27 AM Christoph M. Becker <cmbecke...@gmx.de> wrote: > > > > On 11.07.2018 at 17:19, Björn Larsson wrote: > > > > > Den 2018-07-11 kl. 02:41, skrev Levi Morrison: > > > > > >> On Tue, Jul 10, 2018 at 12:59 PM Pedro Magalhães <m...@pmmaga.net> wrote: > > >> > > >>> On Mon, Jul 9, 2018 at 6:31 PM CHU Zhaowei <m...@jhdxr.com> wrote: > > >>> > > >>>> I don't think we have an agreement on dealing with non-existing > > >>>> value, and > > >>>> the way this RFC proposed, just returning null without any > > >>>> notice/warning, > > >>>> is wrong IMO. I know we already do this in other array_* functions, > > >>>> but we > > >>>> cannot keep making mistakes just because we already made same mistake. > > >>>> > > >>> I voted no for the same reason. I'd even say that introducing a new > > >>> array_ > > >>> function that still accepts non arrays just to return null with a > > >>> warning > > >>> doesn't make sense at this point. > > >>> > > >>> With that said, I'd gladly vote yes if there would be a way to > > >>> distinguish > > >>> array_value_first([]) from array_value_first([0 => null]). > > >>> > > >>> Regards, > > >>> Pedro > > >> To safely use it a call to empty or count or something needs to happen: > > >> > > >> if (!empty($array)) { > > >> $value = array_value_first($array); > > >> // do something with $value > > >> } > > >> > > >> This is okay, but not great. Compare that to the design that returns a > > >> tuple though: > > >> > > >> if ([$_, $value] = array_first($array)) { > > >> // do something with $value > > >> } > > >> > > >> People who argue against the tuple because they don't like the design > > >> need to consider the bigger picture. The tuple way is less code, > > >> serves more use cases with fewer functions, and I even [implemented > > >> it][1]. If the array destructuring behavior seems unclear we can > > >> simply put an example in the manual pages for these functions -- > > >> problem solved. > > >> > > >> This is not how RFC feedback should be handled. I hope more people > > >> vote no so we can reject this do it properly. > > >> > > > I do like this approach with two functions array_first & array_last > > > returning > > > a tuple. However, voting is underway and it looks like it will pass. > > > > > > I wonder what the RFC author (Enno W) thinks about that approach? > > > > This already has been discussed weeks ago, see > > <https://externals.io/message/102245#102317>. > > > > -- > > Christoph M. Becker > > This was not discussed, it was discarded. Enormous difference.
As an example, it was claimed: > If I use a function I expect it to give me a return value which I can > use without any further post processing $wantedValue = > fancyFunction($someInput); But this isn't true even for the array_value_* functions. There must be pre or post processing because of error conditions. This was pointed out by myself and others, but it was still ignored. This is what I mean by discarded, not discussed. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php