Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127826 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 lists.php.net (Postfix) with ESMTPS id 6AE0C1A00BC for ; Tue, 1 Jul 2025 14:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1751380805; bh=4ORwMa2YEHjRvLmExBuxJnFYf1DBMIM/RGs7+FnmMNc=; h=From:Date:Subject:To:From; b=g/Dtwq+Vfv+Yr8RGpLVKEDztYuwm6Uzkkjq1is//BcVaGNeqHb36gCJ26hXXVSHwS t/VJ6hwDlB4M1QsQHrtnC8eNJR8PsrWl8slz7OHB4f+ILimoDkAC5trZzjywq4Zs3u aHyNZHZQdTZnt3cnTHHp1Nrb37NPkOYl3yPIqhqOnpE6ix89svsgFlQJvlwqqGaV9m MeJIiFNlDqPvMZBqRS473l5LDqPx8Zj9w8tnVbHwOEoGOYJXLHH+VZjzZlTFDH2jer tkupglm0/YKm65kG8jULg8RUOtz6a1Ql7rNMkspjbCm/56BoiqTYtv72D/h1LnJ6fC lZ1eKrRzi3T5w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 739C7180047 for ; Tue, 1 Jul 2025 14:40:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) 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,DMARC_MISSING,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) (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, 1 Jul 2025 14:40:04 +0000 (UTC) Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-60f24b478e3so1618853eaf.3 for ; Tue, 01 Jul 2025 07:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zonu-me.20230601.gappssmtp.com; s=20230601; t=1751380917; x=1751985717; darn=lists.php.net; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=PBZD0SeIWSJfT8Sukbk/HZC17JMEkaQvRIVKGAzYr18=; b=qYO7pG2dPVu0O8W2AHpXmg2Pz7o7Q3buAgpuwiM7c1Ztee08r/vTRkawmX+eSp7I3o YlLE/M6n661QHU1WvM7Fwif+cVHBIsp0HmIG7Nd2KJI+HnZsHeLjsX+yAYNf9C1gGpVw mXs6m2CO9EMiuBgUpvPBihc/vWRqMNV+WrqYeKo0fZ9b7QBv8V2+7QFAj5f6yihn7uG2 YS4x3Hx9uVvgsV6sz5VFYReAcwSH5kIgXrok1IXNw3G8g5guVoDbOU/lIpLaApTVyZTD lhYWU6mVPaukKISaPQNehk2BdUx3IKKO03oaBaCB3kHC2TL3BSweMv2x3JUtZ8sypDH1 5tqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751380917; x=1751985717; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=PBZD0SeIWSJfT8Sukbk/HZC17JMEkaQvRIVKGAzYr18=; b=IvmdOcqIOvPrrqLTAwpd5KxqOQ2XF2l0fBeW4znWjB+KLatPKc8wilkpBWmwTyxjB/ Io/fhIfKHdkW0dovjL7Ceq1EnT6qsZx0Lik5IOWWok6jtNhiIm/MyZCM9qibkanZb5z2 XiubHbLXEPGVRws1p4nG0HPIyWerEkuLeuV5QInBiRZ+ak2wZREqYmjyJT6sFjfgSM9b ckY0So2hm6vFu58Fb5ZSPGUVRQ+74uO0cJB8QoOlDCopR8lHvxX2QkCMjC+HnXmWXGNL 3ulH69e3AP09lXDtdypirjEe//VMwVq3b1+csEKUKSHt/Vt4Yr5ySjn4+mzBK0rAyq20 Bjeg== X-Gm-Message-State: AOJu0Yz0t5UAsXNJyEqCDg1yORQBkEfQckGxbVAj+A2taLelbEvAiXl1 6lXlxrGUOhZV/jsT99P9zGfIN/BTZFxX2b+NQfH/IXq+eELhnHhPRAQElawXloGbDAUylzfCBtP 2yquCB+ieLb0kTNDGbXYdz9YA+kiXcQ0EzJOMgo5GnTiB8bu8bhq/SH8= X-Gm-Gg: ASbGncukUtxbBQJqpXlwR8R84x4haUaxWkj19GJ0of/DDVqjPixAts6vq+USmPJKJZt C/S8WgV6B++U0kDbgqpcUCaukBlLvRaQ+uWgoaacaB9+nSJCqLZ12sSJzmPyS2jS1bK/rRTrDyW Jwn19HRDYQWx/3FKDZWCE1Wril4sw4MFcU7ebwMuDtub70tQ== X-Google-Smtp-Source: AGHT+IEekMGLFNJEAYlfGgVNGDSY7+6emuMIxuKch/6h6zW/F5zXtz3EDFGcH32S6FpKbl07tifzbywwoBDjfw/j/o0= X-Received: by 2002:a05:6820:1888:b0:611:b00b:baa with SMTP id 006d021491bc7-611b90f9123mr10818303eaf.3.1751380916716; Tue, 01 Jul 2025 07:41:56 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Tue, 1 Jul 2025 23:41:45 +0900 X-Gm-Features: Ac12FXx_9fCjmkkJYjtIrWfi74_Qox3AhLv-3UzyynKIfqUtJl51n0M8unuIF2w Message-ID: Subject: [PHP-DEV] Expanding the scope of the #[NoDiscard] attribute To: internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000685a5a0638df2580" From: tadsan@zonu.me (Kenta Usami) --000000000000685a5a0638df2580 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi internals, I'm writing to start a discussion about expanding the use of the newly accepted #[NoDiscard] attribute. I believe this attribute is a fantastic addition that will help prevent many subtle bugs, and we can make it even more effective by applying it to a broader set of core functions. My initial thoughts for strong candidates are: - All is_* prefixed functions - The password_*() functions - Most string functions: Many string functions like strlen(), substr(), trim(), and str_replace() are also clear candidates. We would naturally exclude functions with output side effects, such as the printf() family. - Mathematical functions - Pure array_*() functions: Functions that don't accept callbacks, such as array_keys(), array_values(), array_reverse(), and array_unique(), are also strong candidates. Their return value is their only result. On the other hand, applying this to all array_* functions is more debatable. For example, functions like array_map() and array_filter() can be used with callbacks that have side effects (impure functions). In such cases, the return value might be intentionally discarded. Applying #[NoDiscard] to them could lead to false positives for legitimate code. This nuance extends to other areas, like many filesystem functions which require case-by-case evaluation. A tricky example is file_get_contents(). At first glance, it seems like an obvious candidate. However, despite its name, it can be used to send external HTTP requests where the primary goal might be the side effect of the request itself (like a webhook ping), and the returned content is intentionally ignored. Adding #[NoDiscard] here could create issues for existing code. This might be a type of change best reserved for a major version like PHP 9.0 to avoid backward compatibility breaks. Finally, I would love to hear the community's thoughts on the timeline. Should we aim to add these attributes for PHP 8.5, or should we introduce potentially breaking changes like these more gradually, perhaps leading up to PHP 9.0? Thanks, Kenta --=20 =E3=83=BE(=E3=80=83=EF=BC=9E=EF=BC=9C)=EF=BE=89=EF=BE=9E=E2=98=86 Kenta Usa= mi (=E5=AE=87=E4=BD=90=E7=BE=8E=E5=81=A5=E5=A4=AA) github.com/zonuexe ; https://tadsan.github.io/ --000000000000685a5a0638df2580 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi internals,

I'm writing to start a discu= ssion about expanding the use of the newly
accepted #[NoDiscard] attribu= te.
I believe this attribute is a fantastic addition that will help
p= revent many subtle bugs, and we can make it even more effective by
apply= ing it to a broader set of core functions.

My initial thoughts for s= trong candidates are:

- All is_* prefixed functions
- The passwor= d_*() functions
- Most string functions: Many string functions like strl= en(),
=C2=A0 substr(), trim(), and str_replace() are also clear candidat= es.
=C2=A0 We would naturally exclude functions with output side effects= , such
=C2=A0 as the printf() family.
- Mathematical functions
- P= ure array_*() functions: Functions that don't accept callbacks,
=C2= =A0 such as array_keys(), array_values(), array_reverse(), and
=C2=A0 ar= ray_unique(), are also strong candidates. Their return value is
=C2=A0 t= heir only result.

On the other hand, applying this to all array_* fu= nctions is more
debatable. For example, functions like array_map() and a= rray_filter()
can be used with callbacks that have side effects (impure<= br>functions). In such cases, the return value might be intentionally
di= scarded. Applying #[NoDiscard] to them could lead to false positives
for= legitimate code.

This nuance extends to other areas, like many file= system functions
which require case-by-case evaluation. A tricky example= is
file_get_contents(). At first glance, it seems like an obvious
ca= ndidate. However, despite its name, it can be used to send external
HTTP= requests where the primary goal might be the side effect of the
request= itself (like a webhook ping), and the returned content is
intentionally= ignored. Adding #[NoDiscard] here could create issues
for existing code= . This might be a type of change best reserved for a
major version like = PHP 9.0 to avoid backward compatibility breaks.

Finally, I would lov= e to hear the community's thoughts on the
timeline. Should we aim to= add these attributes for PHP 8.5, or should
we introduce potentially br= eaking changes like these more gradually,
perhaps leading up to PHP 9.0?=

Thanks,

Kenta

--
=E3=83=BE(=E3=80=83=EF=BC=9E= =EF=BC=9C)=EF=BE=89=EF=BE=9E=E2=98=86 Kenta Usami (=E5=AE=87=E4=BD=90=E7=BE=8E=E5=81=A5=E5=A4=AA)
--000000000000685a5a0638df2580--