Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126468 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 D34E91A00BC for ; Thu, 20 Feb 2025 19:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740081048; bh=M+s0Ms1WULSYOWN7s+beddNoj75yL+nKbiS/h49bm8o=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=dMbjZj8bRpJOv3+Y0JaaIzH7uCsXbq5htfcn0QfVRjdcqHfz7138gpRGKcyAAKDu7 CdsnRSlarlFvXS2xqhxUASxszATqBdfnD4xOgfzj9a6DDtlc0ZFCUc5R7F1sKbX3u5 3ZGAqrtR7pl0H3Mt8IvJZ8rC1R589DJI4shMF6lyaNhry5Vwu2pMgJtDj6mxnqU8Zx J1sj2q4TQw9vGRK+dR/PVJaisfz9JmIY+snZV4lvMDyFHQcA669o6dHZ9ZkYIV3Qde WWw+fkqAFvEbEHbCZN7yMHPZP4AIzT3vyZ43zVSSW+/4LreBBbPJzZzZD/qmEIUyun /10ppQgylXRQg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 32B21180068 for ; Thu, 20 Feb 2025 19:50:47 +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=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from fout-a5-smtp.messagingengine.com (fout-a5-smtp.messagingengine.com [103.168.172.148]) (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 ; Thu, 20 Feb 2025 19:50:46 +0000 (UTC) Received: from phl-compute-13.internal (phl-compute-13.phl.internal [10.202.2.53]) by mailfout.phl.internal (Postfix) with ESMTP id 8DDBE13808BB; Thu, 20 Feb 2025 14:53:26 -0500 (EST) Received: from phl-imap-09 ([10.202.2.99]) by phl-compute-13.internal (MEProxy); Thu, 20 Feb 2025 14:53:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:cc:content-type:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1740081206; x= 1740167606; bh=M+s0Ms1WULSYOWN7s+beddNoj75yL+nKbiS/h49bm8o=; b=n E7LCqo60wFeLddZoe5aUxKNP4a/4gZJkCuhellO+41vrOPP/tAk42vRcEHMW5tBC duqmcB72/8q6hrIP//TBC352Zvt3iArZ806Xxm36Vd1hvpDygLRgyVchtVvtaWQ9 YKZy2fIz229NOC9M1gk5ywV9hPNPTxawB6/mQWjX7ohAV7oByfNR19xpslxWa2Wj +tH+Nqbq1IYWJuFx/QKqjmmahP23heF2FUvbTa6O9fdCHt7p3pB8b2kEDuh+4IFj JvUAs0kZAPPffX7eryCtC1XXdYNM7sY4/5ns/JdVqzIMMdtJ06Dc2xl0fkoTYaRD PPyL2ZPZFwN0ISeSTUOig== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1740081206; x=1740167606; bh=M+s0Ms1WULSYOWN7s+beddNoj75yL+nKbiS /h49bm8o=; b=iqDKS4Jnm9gfvVa3fW/yGvFC8sERERIg12DC4kU6TpUCD/S1xj5 RM0IiSdtIseIlDDgf3a39RQ7Hwfrdjskh2QcWbK9d7Yn9W/4+ts4ZzwkF6V0AvZu Ry9wc6fXAzeYSiIxr5JQY2XuvW09NM+H8/OR/mZlW3qtn4lp82RyTHGPiBMsBiJE OSEfEptLGXUNGJejJdd3BUOiOAxZ+aadlcOq1ytbEQ/U6FSizRUG3UpUZL19cVy3 AhFdVkeL/EycFashY/47BgLOuMuXQcm31jL0u2ujisHw91Q3YFrYbNJYPscATRlC BjPSE0npAev7sYOscsRRpa/mqdTQ1Ndw4/A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdeikedttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpggftfghnshhusghstghrihgsvgdp uffrtefokffrpgfnqfghnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivg hnthhsucdlqddutddtmdenucfjughrpefoggffhffvvefkjghfufgtsegrtderreertdej necuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothhtlhgvugdrtg houggvsheqnecuggftrfgrthhtvghrnhepteeiieegjeffffehgfeitdejfffgfeduudfg fefflefhkefhgedvgfdujeffuddtnecuffhomhgrihhnpehgihhthhhusgdrtghomhenuc evlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgssegs ohhtthhlvggurdgtohguvghspdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpoh huthdprhgtphhtthhopehinhhtvghrnhgrlhhssehlihhsthhsrdhphhhprdhnvghtpdhr tghpthhtohepvhholhhkvghrsehtihguvgifrgihshdqghhmsghhrdgtohhm X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 42FB778006A; Thu, 20 Feb 2025 14:53:26 -0500 (EST) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 20 Feb 2025 20:53:04 +0100 To: "Volker Dusch" Cc: "php internals" Message-ID: In-Reply-To: References: <95a69ca549b246c3645f8c6db519f669@bastelstu.be> <46f5a4ab-ae85-4a15-9781-27a94eedc512@app.fastmail.com> Subject: Re: [PHP-DEV] RFC: Marking return values as important (#[\NoDiscard]) Content-Type: multipart/alternative; boundary=97334fef8ef24f66b75ea92a89a3e733 From: rob@bottled.codes ("Rob Landers") --97334fef8ef24f66b75ea92a89a3e733 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, Feb 20, 2025, at 16:54, Volker Dusch wrote: > > On Wed, Feb 12, 2025 at 9:57=E2=80=AFPM Rob Landers wrote: > Hey Rob, >=20 > Sorry for writing the mail again, I just noticed I forgot to include t= he list on my first reply to you, also corrected a mistake in the second= paragraph. >=20 > > There will eventually be a php 9, where BC changes will be possible. >=20 > I don't assume PHP will change the behavior of widely used core functi= ons to throw exceptions in PHP 9 as the BC impact will be colossal, hurt= ing adoption. Or am I misunderstanding you here? >=20 > The point that there might be arguments over usage in internal code is= why we went with an "only if it is a clear problem, especially when the= function has important side effects" policy to avoid this. There are no= t a too many examples in core, more in userland.=20 I was merely pointing out that if you were to want to make BC breaks, yo= u can. You just won=E2=80=99t get it :soon: >=20 > > I have to stop you here. It is absolutely NOT safe and reasonable to= ignore the output of array_pop. You popped it for a reason. If you just= care about removing the last element, then you should use unset. Unset = gives the intention. If I review code with array_pop, I=E2=80=99ll spend= quite a bit of time checking that it was intentionally ignoring the ret= urn value (and leave a comment of the same, asking to use unset instead). >=20 > There are plenty of codebases where array_pop is used for this reason.= Identifying the last element of a php array. `unset($foo[array_key_last= ($foo)]);` is only possible since 7.3 and not widely used. array_pop is = also shorter and faster for the same effect (when used on unknown array = shapes ofc). The examples are plenty https://github.com/search?q=3Drepo%= 3AWordPress%2FWordPress%20array_pop&type=3Dcode >=20 > Regards, > Volker This feels like a rationalization, and not a reason. It has a return val= ue, and there are more expressive ways to remove a value from an array t= hat makes the intention clearer. If you aren=E2=80=99t using the return = value, you should make it clear that is the intention. That=E2=80=99s wh= y I said it should be included in this, for exactly the rationale you ga= ve. It IS faster, but it clearly has a side effect that should be used o= r intentionally discarded.=20 =E2=80=94 Rob --97334fef8ef24f66b75ea92a89a3e733 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

=
On Thu, Feb 20, 2025, at 16:54, Volker Dusch wrote:
> On Wed, Feb 12, 2025 at 9:57=E2=80=AF= PM Rob Landers <rob@bottled.codes> wrote:
Hey Rob,

Sorry for writing the mail again, I just noticed I forgot to in= clude the list on my first reply to you, also corrected a mistake i= n the second paragraph.

> There will eve= ntually be a php 9, where BC changes will be possible.
I don't assume PHP will change the behavior of widely= used core functions to throw exceptions in PHP 9 as the BC impact will = be colossal, hurting adoption. Or am I misunderstanding you here?

The point that there might be arguments over usag= e in internal code is why we went with an "only if it is a clear pr= oblem, especially when the function has important side effects" policy t= o avoid this. There are not a too many examples in core, more in userlan= d. 

I w= as merely pointing out that if you were to want to make BC breaks, you c= an. You just won=E2=80=99t get it :soon:


> I have to stop you here. It is absolutely NO= T safe and reasonable to ignore the output of array_pop. You popped it f= or a reason. If you just care about removing the last element, then you = should use unset. Unset gives the intention. If I review code with array= _pop, I=E2=80=99ll spend quite a bit of time checking that it was intent= ionally ignoring the return value (and leave a comment of the same, aski= ng to use unset instead).

There are = plenty of codebases where array_pop is used for this reason. Identifying= the last element of a php array. `unset($foo[array_key_last($foo)]);` i= s only possible since 7.3 and not widely used. array_pop is also shorter= and faster for the same effect (when used on unknown array shapes ofc).= The examples are plenty https://github.com/search?q=3Drepo%3AWordPress%2FWordPress%20array_po= p&type=3Dcode

Regards,
Volker

Thi= s feels like a rationalization, and not a reason. It has a return value,= and there are more expressive ways to remove a value from an array that= makes the intention clearer. If you aren=E2=80=99t using the return val= ue, you should make it clear that is the intention. That=E2=80=99s why I= said it should be included in this, for exactly the rationale you gave.= It IS faster, but it clearly has a side effect that should be used or i= ntentionally discarded. 

=E2=80=94 Rob
--97334fef8ef24f66b75ea92a89a3e733--