Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121397 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 76833 invoked from network); 18 Oct 2023 15:04:51 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 15:04:51 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1F1B0180507 for ; Wed, 18 Oct 2023 08:04:51 -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, 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-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 08:04:50 -0700 (PDT) Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-6cd09f51fe0so291820a34.1 for ; Wed, 18 Oct 2023 08:04:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697641490; x=1698246290; 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=F5EztYgyhQweYbyXfmr09O1M7AxRAJSYoW3qPySEhAo=; b=EM2OURi/lVGwzhkj/hg1b+VeY+6i7IH46AKnmcOPZUZ96xUAHXzdcrL5g3ryHhMGsb 98t5TTYmaVh8GxbQfQQNly5CfqTtbQHz1IWw+KmPFSc3hTMUte5vu6IYA/l5ZFTKIIT2 xxA/TVXNcM5vzzokTJsVlzweIdzcZol5CsIMNHOk4arMpPy4hx6EQZkb+YWN06j0MiZ7 qj3rkvbiAQSqlrLGEYNGC2blcdmzH0gvTOjHr1ojYXKAcafb0M2rO9AohlEchPw3SKhf 5WUXEueLtSvEFuGa79tjHX6KJP1OERzLS/WX96oY1eglYXUNb4dAETnqX/4ST+Ip8dgB uOCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697641490; x=1698246290; 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=F5EztYgyhQweYbyXfmr09O1M7AxRAJSYoW3qPySEhAo=; b=hQdI0H9NOSc4CPR3f4u7bPmUGWVmf8+oU0EAgd6H5SM7McNCFLDupHkczUBY+VKNv7 lOC077XMMdoPevD+ste5+NsK48uLhNe+DU8ERvFn43CH2iZaV41Q4BuAazEWjeRgYVim HrE0CaOMZ9yG98tX+4802f46OEKazzvkj/ewFIShmHyDfmqMyyQMPUD3Upqg2EBkZpJi 5HLecHnMIQ+6inDoSV39YVKEuWlN52pjk43CsjPkdDOF25VSNduzEyY3p7MRqey40Un7 2qy30ZKw44pehwRC6Tl48JOUQXPpMTwB7EiBDf87t8Ij13dOmdJcAq7/rlGJ+Cr3QAZd I35Q== X-Gm-Message-State: AOJu0YyXktbo39yW2FN2tn9AR/RSClwyniVIwX/hV5h+RDfhs7qBSHK0 Um8eBhs9OOhjU16w7KVuTSd2xOFw1rpvMtP6F1Q= X-Google-Smtp-Source: AGHT+IFKM/Dfk+kKGhjksKR5ijpW2X9XAcFWm4DkyQDVdgwz4Gl5rEqharnZc+DwNt/JBzszVisPetFRiWcNuQbPKAY= X-Received: by 2002:a9d:6741:0:b0:6bd:be5:daa2 with SMTP id w1-20020a9d6741000000b006bd0be5daa2mr5503450otm.33.1697641489746; Wed, 18 Oct 2023 08:04:49 -0700 (PDT) MIME-Version: 1.0 References: <173ca550-71a0-4bd4-96f2-b64b6155115a@app.fastmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 17:04:38 +0200 Message-ID: To: Deleu Cc: Brandon Jackson , Saki Takamachi , 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: landers.robert@gmail.com (Robert Landers) > I completely understand what you're saying and I don't disagree with the = thought process. What I disagree with is your statement that you will alway= s use array_first() together with array_key_first(). When talking about sta= ndard lists (indexed from 0 to upper-bound), array_first() is an order of m= agnitude more useful than array_key_first() as we always know what the firs= t key is: 0. This is simply not true, 0 is not always the first key in a list, especially after filtering it. Hence there is a need for this function in the first place. > Here's another thought process: suppose PHP never gets array_first(). In = your Fiber scenarios, you need to use `array_key_first()` and `$array[array= _key_first()]` and deal with any edge cases around this. You have found iss= ues, dealt with it and you're now aware of them. It's really nice that you = want to avoid others from going through the same pain as you did, but the f= act is `array_first()` or `$array[0]` is not only ALWAYS used together with= needing to know the key or not ALWAYS used with Fibers. PHP chose to implement Fibers in this way and it should be cognizant of them when implementing new features. That's all I'm saying. Whether anyone who matters, actually cares, is another story. All I can do is say something. You can only lead a horse to water, after all, you can't force it to drink. > What I'm saying is: don't force a design functionality only for your use = case, especially as basic and fundamental as PHP Arrays. I don't want to be= forced to write `[$value, $_] =3D array_first()` just because there's a co= rner of PHP functionality that needs special treatment. If this was fibers_= array_first() I wouldn't mind at all. If we went with the array return scenario: // assuming it is in [value, key] form [$value] =3D array_first($arr); [,$key] =3D array_first($arr); [$value, $key] =3D array_first($arr); Or with the approach I suggested: $value =3D array_first($arr); array_first($arr, $key); $value =3D array_first($arr, $key); I don't think this is asking for much, nor complicated. Both approaches seem simpler and less verbose than: [$value, $key] =3D [array_first($arr), array_key_first($arr)]; At the end of the day, I'll be happy with any solution implemented, because it is still far better than what we have currently. Robert Landers Software Engineer Utrecht NL