Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121350 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 22509 invoked from network); 17 Oct 2023 15:16:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Oct 2023 15:16:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0A5F01804B0 for ; Tue, 17 Oct 2023 08:16:57 -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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, 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-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (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 ; Tue, 17 Oct 2023 08:16:56 -0700 (PDT) Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-1dd22266f51so370509fac.0 for ; Tue, 17 Oct 2023 08:16:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697555816; x=1698160616; 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=XtO/9Gq6vgVmGYbvN6QY/i+liVn4K2Xy3t6KGnh57MA=; b=xQjpncnNGafqekh7W6qoESnW9q7nC7OOimD7lbn63SbUUrBg8KvHRokm3UafXU4XaV ql9iw5zEWAvRXKs73q1XD7Lyr6fqS+Mi0M6ynSf+l5DQlJnxrVAzIMCOJFiPPpuDdrX2 wwLW57D0vOl1zOIStVNEvmoAJaUGZRhlcZEiZaxJFcqp+zRtGJkood0C1dFOoPaON03V SZIWhQ0vN8CZxlYMSf3rG1qlssNVwCvg/nrslNg/g6CwWM9IyHke7Su0uM8XrRlm61Xg QYiuDhysNZnODITXrVQA/N0kDm3jXwhcaQE4APMUBTC/Nwgv1W1y99bYrJUaaL4Pa/ob FStw== X-Gm-Message-State: AOJu0Yy6i5Nh6QY7Qyy1O7Sezg764cRAbYDnQblv+rZV/GzAh4POW0Ot dApjYKvdU/84lhP8NV40qAbuNZrQ5hZC7jPfOyM= X-Google-Smtp-Source: AGHT+IEL0rW577dHbqhq/ezBGr/eDPdyEtnmCZCcG0jYFia5WYGrrShUYODlII+9zqRAOUv18s7E1IkUxZHCtXn+w5M= X-Received: by 2002:a05:6870:1f0d:b0:1e9:e605:27a1 with SMTP id pd13-20020a0568701f0d00b001e9e60527a1mr2392178oab.2.1697555815667; Tue, 17 Oct 2023 08:16:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 17 Oct 2023 16:16:44 +0100 Message-ID: To: Robert Landers Cc: Aleksander Machniak , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000611f3a0607eb03c8" Subject: Re: [PHP-DEV] Two new functions array_first() and array_last() From: kguest@php.net (Ken Guest) --000000000000611f3a0607eb03c8 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Having array_value_first and array_value_last to match the existing array_key_first and array_key_last functions make sense, and would seem to me to be more intuitive than function names that would not match that scheme. On Tue, 17 Oct 2023 at 10:41, Robert Landers wrote: > On Tue, Oct 17, 2023 at 11:37=E2=80=AFAM Robert Landers > wrote: > > > > On Tue, Oct 17, 2023 at 11:34=E2=80=AFAM Aleksander Machniak > wrote: > > > > > > On 17.10.2023 11:29, Robert Landers wrote: > > > > $value =3D array_value_first($array, $key); > > > > if($key =3D=3D=3D null) // handle error > > > > else // do something with $value > > > > > > > > You can also freely ignore the key, if you don't need it or care > about > > > > error checking. That would save doing two function calls on the sam= e > > > > array, just to do some error checking. > > > > > > > > > > Please, no. What's wrong with count() or empty()? > > > > > > +1 for array_first() and array_last(). The only problem is probably a > > > big BC break. I myself have array_first() defined in my framework. > > > > > > -- > > > Aleksander Machniak > > > Kolab Groupware Developer [https://kolab.org] > > > Roundcube Webmail Developer [https://roundcube.net] > > > ---------------------------------------------------- > > > PGP: 19359DC1 # Blog: https://kolabian.wordpress.com > > > > > > -- > > > PHP Internals - PHP Runtime Development Mailing List > > > To unsubscribe, visit: https://www.php.net/unsub.php > > > > > > > Hey Aleksander, > > > > > Please, no. What's wrong with count() or empty()? > > > > Nothing. Why not either one? You don't have to use the $key variable > > and you can use count() or empty(), but for me personally, it makes a > > lot of sense. > > Ah, I just realized why it makes a lot of sense, and that is when > Fibers get involved. The value and key could change underneath you > from one function call to another. > > $key =3D array_key_first($this-array); > > // call something that suspends a fiber and results in $this->array > being mutated > > $value =3D array_value_first($this->array); > > // $value and $key may now point to two totally separate things. > > I've been bitten by this with Fibers a few times now (or things very > similar to it). > > Having a way to atomically get $key and $value would be a boon, not a > hindrance. > > Robert Landers > Software Engineer > Utrecht NL > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > --=20 http://about.me/kenguest/ --000000000000611f3a0607eb03c8--