Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126466 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 DC7B91A00BC for ; Thu, 20 Feb 2025 15:54:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1740066724; bh=ZKfKO63HhDgzS3DuoJ2gU/QDDMtJFQHsPFa01yJP/y8=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=D4stWPq+L4b9/SNQGDxoRuoGM1IrZFBYDc1hn9Pp/DR31nM09hIDpT0C1hVw6lHUh NqF/uQw6oRfQvyWtVNC/nhrsRuFWny2niZU6qVkZU/+wLz+P8XBpp8GjTQQCjleHTt tAUB65GZ64BpDdBu+1XCNhxJPT04P3+fbRYwkHfL6CnAsFD6sbjjXyc3jxmKyBwzHh kCLvez4/F3k1PvCamOD9seW6g6sgav+wcoIxkxotK5UEEZ6OXzjQFBgFpJKZI5gP1Y hoKexgAyjA+nL1n03rQKH32xd8gN97mBFK9ZcZCvJYhm7WQe+lY38+2Zri3pU4GxrI HqdNZ1LQy8czw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A52B1180387 for ; Thu, 20 Feb 2025 15:52:03 +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=-3.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, 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-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 15:52:03 +0000 (UTC) Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5e0452f859cso1700188a12.2 for ; Thu, 20 Feb 2025 07:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tideways-gmbh.com; s=google; t=1740066882; x=1740671682; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ZKfKO63HhDgzS3DuoJ2gU/QDDMtJFQHsPFa01yJP/y8=; b=Ojy8qzV4ynZlNk4Ivb7YDbkpsYBiVOzAosE3Lz7NlS5kzgiBhtZHWGcAZTILgp1z4V EksfNXEzosXqRSi/tie3XEBfIaG1rYY0h+oU2JY6D98VtiPZNlIi6YMNKKKoF/8dwp8O vOqy9J6QKivPLqE3Ty3UNFd1yDJMyXTj7WjCVKQtJd7zXr9AAxBeeDE/egCyxBzPXdRR 43Lbx8ZRsGUWa49bh0V3QKPldwb1rhU3ehL/xPbgQrx8djf8PKE0Vu0JaMLNIIZI4duC Kx43a/sNHrL7fYo4+x0xLHjOtzSS01a3D1A+k8HcYS9mq6m5s6BNSXTo6i+iAR2OjoII /NxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740066882; x=1740671682; h=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=ZKfKO63HhDgzS3DuoJ2gU/QDDMtJFQHsPFa01yJP/y8=; b=WmFw++jpQoD1DU+uKvghJbE1p0hYKD47h3J/+8n01I6cE+xx9uoEZQUYogtdzzy6ZW 2YcyWsDvIYPSo+aIY9QG52PHcDs17JJ2mwXEpPp4C5G7x4l8mNO4Efo3BiW1NJTgWJV5 CiarYZ5a1NexFrG9/g34B8wVCoYOmCe7dtFPQRd77e4b16R4U6oaDOeqYov6oJSOl72j V5T6eILO/ai6oTzcRBhZpo5Ck0VOPCf6OA2qXYrb2DgE00GxHP0o1DxJiAkt67uo4SYA of1BWghAstg+vzZ5kzkFN+9VTkL2Lfizsw5fTmRTuhlIJ2F03VH1mIR04s7Om7ZtuFWe W3Fg== X-Gm-Message-State: AOJu0Yyq6803G8Qi1mNoiRZCIHUvW94UqCIvRYBdBfMm5OOR4pw4HQtG 2TvrXkphjv7v8zw14MNEGKIEFc8LXkpv6khVeydQDWZvPNl0RfMPWcdGHTbKp0tqrWEc5E4xKuW RpacL0ggwBDLRClZ1FjsqsazyCUQqjJCOSEGBwtI6T0c01vk/BFA= X-Gm-Gg: ASbGncu6Uv+0IdNyi7JS8w+4z8ogjmYZ7LEH3agUQT+byPfL0pbyNlGYwAgvnAXGm4N VhS6kXWdVJ0tODfwKXpEh7WztaovnU+YrmzV/IZrVSayklP5qsM0uBm1x68oRbG6OsfXVOJpsfu TAk/FxdEGFY63emi0TkF7+7UZv8ZA= X-Google-Smtp-Source: AGHT+IEkFxL5eMlsHsvhIMHscBT05PfTzVBN4qiRVY06UzsGsB3IiDtBx4DmxsfFQZsxXbdk48TdQDozG/34H3Px40w= X-Received: by 2002:a05:6402:1ed5:b0:5d0:8197:7ab3 with SMTP id 4fb4d7f45d1cf-5e08950fbe0mr8224493a12.3.1740066881892; Thu, 20 Feb 2025 07:54:41 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <95a69ca549b246c3645f8c6db519f669@bastelstu.be> <46f5a4ab-ae85-4a15-9781-27a94eedc512@app.fastmail.com> In-Reply-To: <46f5a4ab-ae85-4a15-9781-27a94eedc512@app.fastmail.com> Date: Thu, 20 Feb 2025 16:54:29 +0100 X-Gm-Features: AWEUYZlqK-k_Wf7KUnexzojhuYpVB_2TslmpRSLGCLSL83MG28b1ZekHSfH1NXc Message-ID: Subject: Re: [PHP-DEV] RFC: Marking return values as important (#[\NoDiscard]) To: Rob Landers Cc: php internals Content-Type: multipart/alternative; boundary="000000000000618d1d062e94e486" From: volker@tideways-gmbh.com (Volker Dusch) --000000000000618d1d062e94e486 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > On Wed, Feb 12, 2025 at 9:57=E2=80=AFPM Rob Landers w= rote: Hey Rob, Sorry for writing the mail again, I just noticed I forgot to include the list on my first reply to you, also corrected a mistake in the second paragraph. > There will eventually 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 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 not a too many examples in core, more in userland. > 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 qu= ite a bit of time checking that it was intentionally ignoring the return value (and leave a comment of the same, asking 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)]);` 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 Regards, Volker --000000000000618d1d062e94e486 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> On Wed, Feb 12, 202= 5 at 9:57=E2=80=AFPM=C2=A0Rob=C2=A0Landers = <rob@bottled.codes> wrote:
Hey=C2=A0Rob,

Sorry for writing t= he mail again, I just noticed I forgot to include the list on my first repl= y to you, also corrected a mistake=C2=A0in the second paragraph.
=
> There will eventually be a php 9, where BC changes will= be possible.

I don't assume PHP will c= hange 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 misundersta= nding you here?

The point that there might be argu= ments over usage in internal=C2=A0code is why we went with an "only if= it is a clear problem, especially when the function has important side eff= ects" policy to avoid this. There are not a too many examples in core,= more in userland.=C2=A0

> I have to stop you here. It is absolutely= NOT 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 sho= uld 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 i= gnoring the return value (and leave a comment of the same, asking to use un= set 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)]);` is only possible since 7.3= and not widely used. array_pop is also shorter and faster for the same eff= ect (when used on unknown array shapes ofc). The examples are plenty=C2=A0<= a href=3D"https://github.com/search?q=3Drepo%3AWordPress%2FWordPress%20arra= y_pop&type=3Dcode" target=3D"_blank">https://github.com/search?q=3Drepo= %3AWordPress%2FWordPress%20array_pop&type=3Dcode

Regards,
Volker

--000000000000618d1d062e94e486--