Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127072 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 56A851A00BC for ; Tue, 8 Apr 2025 16:37:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744130094; bh=x6ljuVo3Y9qQ53bQ5UuVUx56fik6qrt8T5+6se3pInM=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LnqU2MSY5JDOcWRcYby95zY2wM5s6hjidV6F66NCGggLZ/Iutwy4IcrVHkl7m76nA txQJzvgInQJ3VE7xe9bczfQtkGhY/pxc/7qs/ql7mF8B9SY4bUADuGdblywn3RmnbJ aN5RJ3tFa4NonszmMCrcH8qZHf1ulHlCKb4UodHekaHuuvfJm1yALRHVtMrCKlMc+H KTkVJ9RSPDWClQyBE/XlVv3XQnSL5yi8Cgm9Nf9YSyf0rOfJ8JGnw6QvoPLGb3VC2S CV/huYL80vBsizYDwCx2nXPZ7DwKmNAfdi2BCuhV1iv7JlMyWqBI2qLbLbB5eN96bL WqpsI3RmW77mg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E16F5180079 for ; Tue, 8 Apr 2025 16:34:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 8 Apr 2025 16:34:53 +0000 (UTC) Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-39149bccb69so5444516f8f.2 for ; Tue, 08 Apr 2025 09:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; t=1744130237; x=1744735037; 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=RCU4hcfXzkW28xEsRU08txr2My3Fu5LnwXRK0yXvzlg=; b=a/AFbmJStzGuAZsHRwEnLFAcQt6/71jGPmFHtQq6z+ggwKOnSX9URf6rZWt0einaSa eWKYZGg/05P1t/HYIrjE4ZannRkhMRhZZsWjgP55ScZblLgbROeactzpxsjVI/2WgYr2 xW2TNWuMtgqx+EZjEQdnj4zLTNNApxLLP3PLA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744130237; x=1744735037; 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=RCU4hcfXzkW28xEsRU08txr2My3Fu5LnwXRK0yXvzlg=; b=GC/hD4JeI5uk0EkkTb9gjG9qguhs4YmtcMNb0T76FA2RGSk8Grwnuvha3eGykRpb1o o+DuYQDN5ffbi8wNtKNYWbQga6ikKUcJ+39Ipv6pCoUcLrAbHXoY3KoyEXDscQRXKHeb +VGJ9Xytj9eJgogCxKnjcFPJXiFXBfxZdTfuLCHT/WZ1FmpGYGC8wXuS71e8jD+4b60W yNyjvueacEnQuSXIxEa7qzAS5kRr3TuS722i4LacyW+rFTBlC7DdbFUTTaI/R6e4N8Xi p7qFf6c3ZImzAhuTCKF0eT37/TKvkYIXBk7YuG5E2j20DZ3re3DKnRv0Yn48Mz1pDY0x /rHg== X-Gm-Message-State: AOJu0Yxyr1rFyjHfjDlw4dW3Bm1zyR1V1NJJHBSkwwPhuAAGotEOY7K8 CUkFjJ975heBVLd79WV4oyjajQJdhsB8qZa4dtAusbEJypLNWrIeo8TVuNqPKY2CAkluUrwZt/5 rCR2ULsrtNWYyP5xfdBH+IbvofZqnGlI61uYsH95MyS/8hXCRr+4= X-Gm-Gg: ASbGnctuq1doq3/KRg0gRp2w1FPT0B76HcZRvW/wVSFokp96mlBgC+RlW56E1aGx/c4 rM4LNqjKn8DSegi1wFydTk71JNYBHRztM6YO4BKezIXG41fRf828bPKGxwGW4XVW3XCGbxNwrUI vYUYkEZS9jOn9rKZcfpK3GDREGA98= X-Google-Smtp-Source: AGHT+IE19S/eCITcJmlCnkZQWb49VA0tnq6qz07rNRvoW+Mddu9de+JeGSmskA2SJrWb/fXP7Up4F72DYpBXJ3SNsNc= X-Received: by 2002:a05:6000:188b:b0:391:4c0c:c807 with SMTP id ffacd0b85a97d-39d6fd368fcmr11922017f8f.53.1744130236820; Tue, 08 Apr 2025 09:37:16 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <51fcec92-b2ae-482e-920f-c6c991b526c5@gmail.com> In-Reply-To: <51fcec92-b2ae-482e-920f-c6c991b526c5@gmail.com> Date: Tue, 8 Apr 2025 10:37:04 -0600 X-Gm-Features: ATxdqUHP1nKxTSOg1KcFASDowpjeSewK3ybBShYpa2YCkISwhp8t70HNu0PCZT0 Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last() To: Niels Dossche Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: levi.morrison@datadoghq.com (Levi Morrison) On Sat, Apr 5, 2025 at 9:51=E2=80=AFAM Niels Dossche wrote: > > Hi internals > > I'm opening the discussion for the RFC "array_first() and array_last()". > https://wiki.php.net/rfc/array_first_last > > Kind regards > Niels I dislike all the functions where `null` is a valid value, which can also be confused with an error in the operation. However, this is kind of in the grey area for me, because we do have plenty of tools to avoid the error condition. Of course there's the simple if: if (!empty($array) { $first =3D array_first($array); } And if we have a default value that could be used: $first =3D !empty($array) ? array_first($array) : $default; I would prefer a better design tool than returning null, but being honest, neither of these are too bad. As long as our documentation for these functions are helpful but concise about showing how to work around these edges, then I may be convinced to vote yes despite the design.