Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121417 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11001 invoked from network); 18 Oct 2023 17:49:07 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 17:49:07 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E41CD180507 for ; Wed, 18 Oct 2023 10:49:06 -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.9 required=5.0 tests=BAYES_00,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-f48.google.com (mail-ua1-f48.google.com [209.85.222.48]) (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 10:49:06 -0700 (PDT) Received: by mail-ua1-f48.google.com with SMTP id a1e0cc1a2514c-7b64810aebdso2062992241.2 for ; Wed, 18 Oct 2023 10:49:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697651345; x=1698256145; 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=DppJNw4CMM7i6Ue5JQe1+wT91BjXxR+sSvPXakSd+Sw=; b=OmYOnDN6UbKbNbq1Uk6CycRnKXLZgx4a+3DHRO0q7+GX08sSxJGRVqc+4p73CiZ+NI DsIy/lfQFwMpA5fU8TSxa75sF1cL4Mev9nOPPk941RwmFBN08+u/MCshWdICBjnK1VIU XXmJlY531DIVUvgKhATqBCn5r5qP+Z4akMowXtBLJBW8hfAmIbckvJd1ubxbk7urqVC7 TWlI2pZM85y8TRJa8YNVdKoP/a9Pnr0ixC8D5+S3TvmIEUabQh+N4ZnCL/AD7J8L/fNi PcN8BET/seHBevLmwsc8he696hyQAPecAZEqkuBzFKHu74tZIeJvo+APpcEag/JzTd8t 5DgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697651345; x=1698256145; 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=DppJNw4CMM7i6Ue5JQe1+wT91BjXxR+sSvPXakSd+Sw=; b=hyofDIcU6JmsyfShNOgyzSzfZBaqP9w0NCTdtVWtkCN/k0BD9yDkIbZ7ShwZ23ZxA3 I2fDmwVOYP4uZarUgzgmK/otNAztCCQe9mnqcmfVMum1swQfqvuyvjl9+Nus94hb1n/v Cvmzeg0F8KGmpnA1ZsXDnPp4hPi6Gv4HdsjvfsgllwLolelWP2M8B3tW1tRV8gaH6IGb LMC1DHxfdkGTmn4Dx2DDg/H+r78DsYUq0Zj3aeOWsoLJ5sJ0UHOt5ebE5g4fd5jxcsUX vE+ihTmltv5Vm1tK4DJjY2mPKr0Grmzef3/+HT6VwcI1LpQjsR09BW7tDOKMFwL9xhHq BYHA== X-Gm-Message-State: AOJu0YxipOEgqyIUQy8iD1fhDYQLvrABZIzMk+8oXN3A83FLdcUifrBk QwMRJFdCDy1iZ6OtqLLdiXNiRGrkzk/ZkARNCWY= X-Google-Smtp-Source: AGHT+IHn+9xz/4rXu2kkkxv3q7MnT+rVexZHLP3UN3PZIAUCdiDJHwilBYPW+6FFL3Q2vlh4bpZwC+r1VFfO7hGfEmg= X-Received: by 2002:a67:c390:0:b0:458:aa1:e0d6 with SMTP id s16-20020a67c390000000b004580aa1e0d6mr6332064vsj.0.1697651345571; Wed, 18 Oct 2023 10:49:05 -0700 (PDT) MIME-Version: 1.0 References: <173ca550-71a0-4bd4-96f2-b64b6155115a@app.fastmail.com> In-Reply-To: Date: Wed, 18 Oct 2023 12:48:54 -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) > The only portion in your email I disagree with is this ending. I believe = there are enough use-cases where if the first value is "valid null" or "def= ault null" it won't matter. The developer will treat them both the same. Pe= rhaps you disagree with this and want to avoid ambiguity at all costs. My p= roposal to avoid ambiguity would be throwing an exception instead of involv= ing the key because involving the key can be a composition between `array_f= irst()`* and `array_key_first()`. > > Although I would prefer the function to throw, I think it will have the s= ame effect as this key discussion: complicate something that can be simple.= If the developer needs to distinguish between "default null" and "value nu= ll", they are able to do so by running `empty()` on the array prior to aski= ng for `array_first()`. It's actually better than a try/catch, 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. > Ultimately, there's 2 parallel discussion that somewhat intertwine themse= lves: Fibers ("async" code) and ambiguity ("value null" vs "default null") = and while there are options that may cater for both of them, there are also= options that cater only for each of them individually. Trying to over-poll= ute a function as simple as `array_first()` to cater for these edge cases i= s where I think the problem is because userland will always be able to tack= le these issues by wrapping the basic functionality provided by core. My argument was purely for ambiguity and the other reasons outlined. While the possible edge cases from fibers usage arguably may not be a great primary reason to offer such functionality, it is a great supporting argument. > * 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`.