Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102771 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52465 invoked from network); 11 Jul 2018 18:18:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2018 18:18:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=levim@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.208.177 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.208.177 mail-lj1-f177.google.com Received: from [209.85.208.177] ([209.85.208.177:41001] helo=mail-lj1-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/CB-15421-DF9464B5 for ; Wed, 11 Jul 2018 14:18:38 -0400 Received: by mail-lj1-f177.google.com with SMTP id y17-v6so15296196ljy.8 for ; Wed, 11 Jul 2018 11:18:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5aBmQUJ10iutmmGpyPpnCrfShBhnp640OuZNpk3Iz5g=; b=DS5s8vyJJzFnid8bJ7MbJsEclLirXPcQHVnDVasik+ZwCe0Src+nmgioHTPT7DxfL7 t2KT5WpfLEZht85DlQ7wPQbMMhTUGSDrbMma3WH2akD9bF5FF3m/BAOyBudw5jmKZ15d iYagAuKIlZRLPDrmXfwAzoROQqKzTSkg0+8Mmma83AiCrsELFwe3EiXaGPLzKn2cabqz o4rxB46r4nVwXJtD783I8jb0aEGEpfEWCHuafLaRbJ3q1wqnR5kmmfEpFh3UkFFs68M2 SPTPK33MSnz+mpBOIRqtxSE9cHfs8+RsKe5KXRlMmJg9USsF+rXm/eHhZTeRPhRsn1bu n/xw== X-Gm-Message-State: APt69E2fCf4IJPv8pcEK00/TKAY4SVD15Ll/QjWdvQvipeHE1uQVkvBo YavCWLJ4q+ZY2/O4K8Z+DwNazoNB5diwsLpUXms= X-Google-Smtp-Source: AAOMgpd5F6vhpqpPOKXqZXyGbcIQUAVgiBqXMqs2zGBt2mlhzeV9BtwyD4WpzzAvQBZpXYs1yG7liKm9vuXqPHNnW2g= X-Received: by 2002:a2e:5243:: with SMTP id g64-v6mr18460271ljb.144.1531333114507; Wed, 11 Jul 2018 11:18:34 -0700 (PDT) MIME-Version: 1.0 References: <13b4eb91-6566-3724-d45d-aa63254e1f58@telia.com> In-Reply-To: Date: Wed, 11 Jul 2018 12:18:22 -0600 Message-ID: To: enno.woortmann@web.de Cc: Christoph Becker , =?UTF-8?Q?Bj=C3=B6rn_Larsson?= , mail@pmmaga.net, me@jhdxr.com, internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Re:[PHP-DEV] [VOTE] array_key_first(),array_key_last(), array_value_first(),array_value_last() From: levim@php.net (Levi Morrison) On Wed, Jul 11, 2018 at 11:42 AM Woortmann, Enno wrote: > > Am 11.07.2018 um 18:20 schrieb Levi Morrison: > > > 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. > > In my eyes being aware of what I put into a function and thus catching > non array inputs and empty inputs before differs a lot from post > processing return values as it increases the comprehensibility of the > code. I also can think of cases where the input format is known and no > further checks are required. > > Additionally the tuple return pattern is not common among the PHP core > functions and I don't know many occurences of this pattern in userland > PHP code neither at the companies I've worked at nor at open source > software/frameworks (correct me if I'm wrong) except the by far outdated > old foreach construct with reset() and each(), thus I assume it's not a > that common pattern for PHP developers to use it in core functions. > > As I pointed out during the discussion we should also watch at existing > functions with the same problem, differ between a valid return value and > an error. > Not all of them can be changed to use different return mechanisms like > the tuple return pattern (eg. array_pop). > > Maybe we can instead think about changing Z_PARAM_ARRAY_EX in a later > stage to not return null in error cases but instead throw an > InvalidArgumentException or something like that (at least for function > calls with an empty array for functions which require a filled array, > for invalid types maybe a fatal TypeError like it's thrown when a type > hinted argument in a userland function is violated is the correct > choice). Would be a pretty large BC breaking change but it would be > consistent among the array functions. > > In my opinion neither rejecting the RFC nor changing it to return tuples > solves the underlying problem. What is the underlying problem in your opinion? My opinion is that the core problem is that these functions cannot be efficiently implemented in userland, at least not the ones that get the last key and/or value of the array. You either need to make a copy or traverse through the whole array. I have been working to solve this by making a bidirectional array iterator that can start at either end of the array and can traverse back and forth. This work will not ready for 7.3, not even with the extension to the feature freeze because there is some design that needs to happen; the work I have so far is here: https://github.com/php/php-src/compare/master...morrisonlevi:BidirectionalArrayIterator