Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121419 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15366 invoked from network); 18 Oct 2023 18:40:45 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 18:40:45 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A2A5018050B for ; Wed, 18 Oct 2023 11:40:44 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-vs1-f42.google.com (mail-vs1-f42.google.com [209.85.217.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 18 Oct 2023 11:40:44 -0700 (PDT) Received: by mail-vs1-f42.google.com with SMTP id ada2fe7eead31-457ad98f603so489174137.0 for ; Wed, 18 Oct 2023 11:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697654443; x=1698259243; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/ptK4Sbqv/0zuGZg7elXi8iOGpzEJe9AYiGsMgghwlI=; b=IIoFjeu4FvTkP4dpF4X8IIJzhBDNTH/4zlqOe3+KeVN7/RIxutXhwUhJC7f95bRz1c 6MKn0q/MGs78Gua21rm510vUvq1+Z6qiBjv2eDvm/wfPVymNd2kqy5htac/vvO9hVFV7 WEVeEvDFHUCfrMRv84uEhYaYWnyqWVtbzCLDdZuxfgfMxCwvDXYBmagn+IunkWTuMHju +uIv9I7l5vVRSSnfGezHXoQ/qfJC+9lLjb+7r/2C1Cl4XlcisV8F0Vo9I4QfYnb0+PRn ZkmsIaLxXTZyFsny0LZi5N3kJ81XqvDEGp6E4eBTrasp38yJZrlfgAZiLpmHOQf5clq7 ACTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697654443; x=1698259243; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/ptK4Sbqv/0zuGZg7elXi8iOGpzEJe9AYiGsMgghwlI=; b=NxHWFzIbg8X8cSYDHcBEMZyjW0ERSO54UPjxpbJZ27XSeeeEPfpw03pInGiYIHtGRL AjwWapRuUZoRzZcoY2WkjA/HOd13DI/l2XoJQfV/geH+gusTnZobIP5koBXEPuBqYppN gRliiI9X/ztNgiRlcK682RQb7T9VgO5rgg0w1QUv+mHBi/ZwvzkKggpaWMPUxddpBY6B MzTjSvUiUK0rtuY/Nwv0TfJCh+pf8x91bW26C94Eig0hH6QVtpKeFTk7qEBFbHxhws0J iVzXVoEZ8j5cKWJch2UW6NnlXJ4HSx7MpoTMxMGCexAw1IE5RQfpeu1CP7gaHSrQ/IhE JA2g== X-Gm-Message-State: AOJu0YzyrA4HTo1uwDYsJW1bhRwGFhohDbZ0yOw6TPrknvlZUn6cYRea ZX1PcRwDfDaDQ1wORDVMHPyN0J9VNSbz+JcVsl0= X-Google-Smtp-Source: AGHT+IGlDj2A6IxgO+M8rs8Bpv1FYUbEPlSvJ6BNIfl4vEWX9Yyd4rmLI9Ocezt2cbtPb3ytWhexbvQxtWvqXGZNZss= X-Received: by 2002:a05:6102:2f8:b0:457:c37d:5d4e with SMTP id j24-20020a05610202f800b00457c37d5d4emr4730684vsj.2.1697654443242; Wed, 18 Oct 2023 11:40:43 -0700 (PDT) MIME-Version: 1.0 References: <173ca550-71a0-4bd4-96f2-b64b6155115a@app.fastmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 15:40:07 -0300 Message-ID: To: Brandon Jackson Cc: Levi Morrison via internals Content-Type: multipart/alternative; boundary="0000000000000a7b22060801fa43" Subject: Re: [PHP-DEV] Two new functions array_first() and array_last() From: deleugyn@gmail.com (Deleu) --0000000000000a7b22060801fa43 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Oct 18, 2023 at 2:49=E2=80=AFPM Brandon Jackson wrote: > > The only portion in your email I disagree with is this ending. I believ= e > there are enough use-cases where if the first value is "valid null" or > "default null" it won't matter. The developer will treat them both the > same. Perhaps you disagree with this and want to avoid ambiguity at all > costs. My proposal to avoid ambiguity would be throwing an exception > instead of involving the key because involving the key can be a compositi= on > between `array_first()`* and `array_key_first()`. > > > > Although I would prefer the function to throw, I think it will have the > same effect as this key discussion: complicate something that can be > simple. If the developer needs to distinguish between "default null" and > "value null", they are able to do so by running `empty()` on the array > prior to asking for `array_first()`. It's actually better than a try/catc= h, > to be honest. > > Sure in many use cases undefined and null can be equivalent, but there > are other use cases and considering the fact that php does not have a > user level "undefined" value. It should at least attempt to not be > ambiguous when possible. Instead of being ambiguous by default, > requiring the user to do additional work to not be ambiguous. > > I do think the method is a great opportunity to avoid ambiguity, > without a huge sacrifice on cost. As you said, throwing an exception > would only further complicate things. Sure an empty check would get > the job done, but again I believe it should not require such > additional logic just to not be ambiguous. > My statement about throwing exceptions is, to me, exactly equivalent to the discussion of $key and $value. I believe being ambiguous is fine in this case. If we collectively decide that ambiguity is unacceptable, then my vote is on Exception over involving $key on `array_first()`. I would go as far to say that if the only option is to have `array_first()` returning $key and $value simultaneously, I probably would prefer if `array_first()` does not get implemented at all. > > * If naming is an issue to you, I'd also be fine with > `array_value_first()`. > If the rfc does maintain only returning the value > `array_value_first()` IMO is ideal. > * With array_first being so general, I would think it's only fair that > the naming is reserved for something that touches on multiple parts of > the array. > * If someone did want to open an rfc adding the above functionality > they would have to opt for something like array_first_key_value which > having a group of key/value operator methods `array_key_first`, > `array_first`, and `array_first_key_value` would be absolutely > atrocious IMO. > * Naming consistency with array_key_first would be nice. For new > comers to the language I think it is a reasonable assumption when you > see array_key_first being used. That array_value_first should also > exist that does the same thing for values, and array_first might be a > slight curve ball. > * They are going to do some googling and probably be pointed to some > outdated way of doing things, like using array slice or back to > array_key_first. As time goes on blogs and other places like stack > overflow will update there solutions, and or people will re-ask hoping > there's a more up to date/efficient solution, and hopefully then > someone will actually provide the latest answer of `array_first`. > Everything you mention about function naming I believe gets invalidated by Larry's comment regarding all of PHP `array_()` function family. They don't have `value` in their name when working with array values and they have `key` when working with array keys. With that, array_first() cannot be "consistent" with array_key_first() without being inconsistent with dozens of PHP array functions. Larry's comment is enough to close down the discussion on the function name as there's no room for anything other than `array_first()` in my opinion. --=20 Marco Deleu --0000000000000a7b22060801fa43--