Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121390 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 50016 invoked from network); 18 Oct 2023 13:11:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 13:11:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 686F61804B0 for ; Wed, 18 Oct 2023 06:11:26 -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=-0.5 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,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-ua1-f53.google.com (mail-ua1-f53.google.com [209.85.222.53]) (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 06:11:25 -0700 (PDT) Received: by mail-ua1-f53.google.com with SMTP id a1e0cc1a2514c-7b0ec7417bdso2356140241.2 for ; Wed, 18 Oct 2023 06:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697634685; x=1698239485; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=f26oJQVzLX114HELR1zzHbCCS823zCu7t1U7KVYUAx8=; b=bY+qdddm8Fti8LLQO4+wh8rjnPV1OdneZwUfybTzgEkY48eysPV9upivcQG7aYsYsP NYYuBbc+09m2DNwYtCwVqoHnmXr/7py59cVk17Il9hi47yEJKpKzqLYaiRXDH+ZuL6w0 dk4Eu5i/9Y1bAPiJiWFt4wvLimTyh7aqg/CTApA6gPHO6xYHq7r4maWzKWLMllYJyDvh Up7nQHna4cvoPAtBe85R/GlikZTn20SxaEjJCeEmWV5l/UUyVnswMcmijNbo7y9j4hBA 4r08ABSu8BjoXOnlesgyxcqeI7U8wEW8BM3emBzhYi9OaRH2hbAHUulP2vvqLoqdvKM0 X2tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697634685; x=1698239485; h=content-transfer-encoding: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=f26oJQVzLX114HELR1zzHbCCS823zCu7t1U7KVYUAx8=; b=wu83fekHy5g63EKPQgFt4rwRGSFIp2M/ti/+1/gQEvunYc9tD1B60iP+9oIhRzKB0t uvmdw4S/iYQCiWW6vEcmPEzu9X5iwLVBZLBTCtR83BFh40t49R1+FdVT8sQdO1VIZB2r WeYAVsJmTfHKx6fi22B+Ie1DL+Rnk02Y5Vo/WT2VE4nWKeH5quPSicfp6VhHq4EisjxG D71WaZcZgGHyZPHcijQnlkcHT/RKBQqveG5aSlB1NTX+dlAmi0cwoqtVzgB7wWd/Doun CsW+zg6aOdjlebtEO4x+ArJ7mWw3wUSoqqCm7na3kjwkAw2W1segyZqu1pmUEz45PKNY zBrw== X-Gm-Message-State: AOJu0YyRKLKIUh8UKtv6HmlAF4fCsxfglhQA8Ef4Yg84a4jn1OD+g2BV hVQo/pRjUkOq+qyYkT5EmLUSLS3JGKbXuvQZopk= X-Google-Smtp-Source: AGHT+IEGVyELgE8htmpqpuHsfDOWhVl83GnuMpoNie/mXGYBcVfFAUtRX6ldDhOwh6odPBZ9znEM5vhGS0BLDWFjwBI= X-Received: by 2002:a1f:b214:0:b0:495:3d9d:535c with SMTP id b20-20020a1fb214000000b004953d9d535cmr5139253vkf.4.1697634684478; Wed, 18 Oct 2023 06:11:24 -0700 (PDT) MIME-Version: 1.0 References: <173ca550-71a0-4bd4-96f2-b64b6155115a@app.fastmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 08:11:13 -0500 Message-ID: To: Deleu Cc: Levi Morrison via internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Two new functions array_first() and array_last() From: brandonja991@gmail.com (Brandon Jackson) > This function signature can be accomplished by userland once we have `arr= ay_key_first()` and `array_first()`. It's much better to keep `array_first(= )` as simple as possible and let everyone build their own approach to go ab= out it since we have so many approaches. The goal wasn't necessarily to keep them together. The goal was to introduce an arguably simple way to: 1. Be able to get the first/last value of an array. 2. Know if the value was actually in existence or not, rather than just blindly returning null when it could be a valid value. 3. Accompany multiple use cases like needing to return a default if not found or throwing an exception. 4. Offer a way to know if the value existed or not and act accordingly without additional logic checking the key. 5. Address the seeming genericness of the function name. * If I were someone who seen the name for the first time. I'd see it and ask array_first what? And proceed to the docs. The different approaches are trying to figure out the best way to know whether the result was the actual value from the array or some baked in language default null. I get your desire to keep things simple, but IMO returning a value that does not conflict with possibly valid values or somehow indicates the value was not present is important, and should come before simplicity. Which likely means involving the key somehow.