Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126377 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 7712D1A00BC for ; Wed, 12 Feb 2025 11:52:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1739360986; bh=u25wGatjrE9prooFCDdfyYxN1LhOTk//hzbeVoYl9mo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WmkROTmUIGmWQzsY9pQMAo2zEkn0wIeXrSuwPLxao1Y6wb1a561z86Q/yFSI5yVQI QrZtpNlZee9blYrF70CLoeaDPfhq+g1uD1Fwnu7P5lzUHfU5Eeh0uMq5w3IjL6jIbO c8z9YSyrCucYNzto4+FBGRhlFTeoFLuE9xfFiravQI56tsoJkBQvwdlFnq5VrI257P FJ7CDfrmH90jjvTkA27n/4ha52GLDHunSUFC+5q92Akn+hQXyzW3tEageIAHsUDa79 D+s+dwoFfUZzbffwGGhTEar4aOW8kLsT62vmGGvoqPRMkHD2eaajGDLgkobtSEmFsL IXjM72bP7bU7Q== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1019118004B for ; Wed, 12 Feb 2025 11:49:46 +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=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.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 ; Wed, 12 Feb 2025 11:49:45 +0000 (UTC) Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-ab7c6fc35b3so533730666b.2 for ; Wed, 12 Feb 2025 03:52:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tideways-gmbh.com; s=google; t=1739361147; x=1739965947; 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=u25wGatjrE9prooFCDdfyYxN1LhOTk//hzbeVoYl9mo=; b=bpxsf+/PZozQvIcGGfa/71uTmGVZ5Fr0RwOAy0pbpbGY7SylQJqv+teol9E4Qw5MZy 0iSCgu/1BGKp7+/B+6Pf+t7YEz2v+BQczrKjjGksJnWhvphersSv9pmI2+/I94rjSeER ABMcnl3vo42EXybJ3P3AR/0pQzJfx17wc9O29XpFx8xsnbvI7TNB8EEwzs2P4u5ezQo0 ZdB5pXbkdmGad0a2rF/h0K6GJy8okFnmo2DLRlRgamapIAbFyQIOdLBzy7mGRq5ynSHC f46u0oNznOFMPoGfR3nzAujiEx62gwqC3EBruP0y7A6qoPieeCkCe8Gl8P1dD0L9aEQn cgDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739361147; x=1739965947; 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=u25wGatjrE9prooFCDdfyYxN1LhOTk//hzbeVoYl9mo=; b=ei+Jc9CqyBJX10neRniqp/i2h9VJRRTl7AtmaoNctCvCvwZzMF7UGlDeJcVrDaABG3 JQy0Slwfng4e5FVqRdMwsDrka5nrpvO6iCiTBZX5MCz1uqVWmO5JIiaepLRhoQ83lqmW xBs64+5ty438jSvQ8Y/5QoFmbyeMqGQUoFuwbQh7ugaPOKev9xcYZcNiC6xV6AMFDEZ2 7aKloX6WB9TeHVRR3gWdWdGKwA82EN/R1BToWHI1vuQxUwdgj+Q6+Q+T5TCZkU8uJyHQ nZBjAYoDCIc+z/TNo/uAhrMxhG1FeFMjwbbbRZ3AP4ZTtdgtWDJb4H5gNBaq1dMWXT0m VnzA== X-Gm-Message-State: AOJu0YyOTHb82j31obrc5ZxaPAFhSYqDc8eGb3/in5I9BtAn3Ne3F50w uY1HzCbAj+HXYiZuaRXSh3up55Atn/klNVMaOwdjEBKezFpGyB5LqX2llF5EYR/tMIHjT6LuJOq MVefOTJc/4lBQhz89+1CG9cJbYI8yedxmMoTDyw== X-Gm-Gg: ASbGncs+xRJHRZuwsgasjR3b7S9LCzhMVaQp7bhCThpVz1FS7eyk8bn4BCVsEXcg75e Kxpa9uiVnvBtysgfcFu9secIp3LYce3koKSR8gziisokxawINOtRMf/DdIilmE3gtTMsiHuRcs+ Q2qxoMusenvgp19W8JjozUD6XjAYk= X-Google-Smtp-Source: AGHT+IF4P2pWCP+rUogTl1bnv8i6sZyeobsJb/XKe9GJw50/1zinK600V8QjkzfR9aHgssjfIOI+6CrqcfLkwtis468= X-Received: by 2002:a17:907:1c85:b0:aa6:9624:78f1 with SMTP id a640c23a62f3a-ab7f3714978mr277805466b.9.1739361147313; Wed, 12 Feb 2025 03:52:27 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 12 Feb 2025 12:52:15 +0100 X-Gm-Features: AWEUYZlTTwjAY7hjhVDks6g8xbCjQ-QRr7seSr9AgqJcVeYyOmO9xcYdG8PX1dw Message-ID: Subject: [PHP-DEV] Re: RFC: Marking return values as important (#[\NoDiscard]) To: =?UTF-8?Q?Tim_D=C3=BCsterhus?= Cc: php internals Content-Type: multipart/alternative; boundary="000000000000528391062df09384" From: volker@tideways-gmbh.com (Volker Dusch) --000000000000528391062df09384 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 29, 2025 at 4:12=E2=80=AFPM Tim D=C3=BCsterhus wrote: > Volker and I would like to start discussion on our RFC to allow "Marking > return values as important (#[\NoDiscard])". > > Please find the following resources for your reference: > > - RFC: https://wiki.php.net/rfc/marking_return_value_as_important > - Implementation: https://github.com/php/php-src/pull/17599 Hello everyone, it's been two weeks, but given the feedback we received, we don't feel the discussion didn't reach a conclusive resolution yet. So we wanted to solicit additional opinions. In an attempt to summarize the discussion, how we see it, there are two main points of contention we'd like to discuss further. a) Intentionally discarding the return value The `(void)flock($fp);` syntax was the main thing discussed on the list. With `$_ =3D flock($fp);` as the most suggested alternative. The issue with using `$_` as it currently stands, is that the unused variable would be cleaned up by OPcache. Should we instead have a special case in OPcache ensuring it does not apply its optimization to a variable if it's named `$_` instead? The semantic difference would be that $_ would keep returned values (and objects) alive and in memory, whereas (void) would discard them immediately. Leading to different times when, for example, destructors would be called. The consequence of this would be that 3rd party tools like IDEs and Static and Dynamic Code Analyzers would also have to build that special case in to not produce "unused variable" warnings. We're also happy to change the secondary vote to "(void) vs $_" as we feel there needs to be a way to discard the return value consistently for this to be a complete and usable feature. b) Naming of the attribute Nobody mentioned this on the list, but before opening a vote we'd like to heard if the attribute name makes sense to you. We've chosen #[NoDiscard] as it's also used in C and C++. See [1] for the full list of references. If you feel this doesn't fit with PHP, we welcome other suggestions. [1] https://wiki.php.net/rfc/marking_return_value_as_important#precedent Kind Regards, Volker --=20 Volker Dusch Head of Engineering Tideways GmbH K=C3=B6nigswinterer Str. 116 53227 Bonn https://tideways.io/imprint Sitz der Gesellschaft: Bonn Gesch=C3=A4ftsf=C3=BChrer: Benjamin Au=C3=9Fenhofer (geb. Eberlei) Registergericht: Amtsgericht Bonn, HRB 22127 --000000000000528391062df09384 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Jan 29, 2025 at 4:12=E2=80=AFPM T= im D=C3=BCsterhus <tim@bastelstu.be<= /a>> wrote:
Volker and I would like to start discussion on our RFC to allow "Marki= ng
return values as important (#[\NoDiscard])".

Please find the following resources for your reference:

- RFC:
https://wiki.php.net/rfc/marking_re= turn_value_as_important
- Implementation: https://github.com/php/php-src/pull/17599=

Hello=C2=A0everyone,

it's been two weeks, but given the feedback we received, we don= 't feel the discussion didn't reach a conclusive resolution yet.

So we wanted to solicit additional opinions. In an a= ttempt to summarize the discussion, how we see it, there are two main point= s of contention we'd like to discuss=C2=A0further.
=C2=A0
a) Intentionally discarding the return value

The `(void)flock($fp);` syntax was the main thing discussed on the list. = With `$_ =3D flock($fp);` as the most suggested alternative.

=
The issue with using `$_` as it currently stands, is that the un= used variable would be cleaned up by OPcache.
Should we instead h= ave a special case in OPcache ensuring it does not apply its optimization t= o a variable if it's named `$_` instead? The semantic difference would = be that $_ would keep returned values (and objects) alive and in memory, wh= ereas (void) would discard them immediately. Leading to different times whe= n, for example, destructors would be called.

The c= onsequence of this would be that 3rd party tools like IDEs and Static and D= ynamic Code Analyzers would also have to build that special case in to not = produce "unused variable" warnings.

We&#= 39;re also happy to change the secondary vote to "(void) vs $_" a= s we feel there needs to be a way=C2=A0to discard the return value consiste= ntly for this to be a complete and usable feature.

b) Naming of the attribute

Nobody=C2=A0mentioned = this on the list, but before opening a vote we'd like to heard if the a= ttribute name makes sense to you.

We've chosen= =C2=A0#[NoDiscard] as it's also used in C and C++. See [1] for the full= list of references. If you feel this doesn't fit with PHP, we welcome = other suggestions.=C2=A0

Kind Regards,
Volker

--
--000000000000528391062df09384--