Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126246 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 5CDD71A00BC for ; Thu, 30 Jan 2025 17:48:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738259166; bh=zGaxizqtNPkC0lyJhDQyVDpk7bAFkkCrpaTZ15IONaQ=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=XAkq43AYEVpRMY9l35LcMMQaicaYZefPxdtX32ESlCawEwM3IOR1rZjOVFtGGTlXn C0mQ1+rp9z0th2n4ZlQGNEea94UxNvnpjZZ9Wl7H8HjAJGxupGJXWzNOq6zs5JsUYy /smv8WScIKbno2I5EfqPQBa9DkIbslGlN1DHvLJirWjUIGTS8Whzwz7reOjfL2IS1u GNFuKbADpc0SSy2RUy3TtU5I3+QTqOx1GVOoDqz6BJk/UANOsoHA0OI6U4WASZgdsi XyhR0HMb7jMyHpLl9KkMHAXVz+IQ18l80mpLsI1ShM6dvICRofA8m+FvtkTvVEJ9aL cLf1xqlMNllSQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DE1F61801E1 for ; Thu, 30 Jan 2025 17:46:05 +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=-1.2 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, 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-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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, 30 Jan 2025 17:46:05 +0000 (UTC) Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-436a39e4891so8064915e9.1 for ; Thu, 30 Jan 2025 09:48:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738259332; x=1738864132; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=uNlyQG/ukntHUS/hEUAOTnHWkTYoS+fsRdyDR2t3OZI=; b=cL/0AbRcvhbI3HE0zpF0ucd0YckQZl5VotjVAlDA1SHvblS8jVmDGzg+RI8Z5xeNbE si4QHMGfFz/mmjRK7Xrp8kHS3fVniCq4g0p9Pe59q8T0th3SSLNUCCB2/fZ4ejvxYAsz okh5cDIs8Z/aqZAZg3u0Jim17Oy9NQJm+jsI07Xm/KCYr1cgiI3O8mOS5PKt9PkooIeF 8jv8nV8pBdpvgVYtMB/3C85h3dnLkFmQguaao0wmaSJr6KhH5Gk7hJ4kw8bTcc3tGHrr 5OYHcs1S8B6C8I+A43EzjHlPZouYOEm0WKKh/ZgMzPlZZobJmHzBWmUz+FIeKYJTt0fv PjvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738259332; x=1738864132; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uNlyQG/ukntHUS/hEUAOTnHWkTYoS+fsRdyDR2t3OZI=; b=ANPQHJ49Pdo7w1X4MjJ8YrqNbMm4p7YEwhfgxXGceisuycVossbiEgBmF3JWDLwfKb cjJ9qtzSJNMAyMY2dei4pJyXt7pYSRjEfwKPrX3KYTb7OzpFoBgOZacDbaxYCYF0E5e0 nqYVKm2AZRGyoC9MPtb7RhmpQ5mEXY/MoCvsA2hSIFyL7UAXsxgoUo7cxpWJ0+52JNWY QKktN4DB9D5BK7vL+wVEsTLmdnOFKTJYmsA3m3NvYCeuokyyIDdwNt209zfE+sZYO9yH OfucPklotNHw5q9T5s1+M+AQ6x0ikgUDnhP7HsrNMGoFwQmzkqgMHTPY7gENK/QjQxO+ R3TA== X-Gm-Message-State: AOJu0YwRxeoiCLHcKj3INe739OiwP0cpiidCm9lsydKW3xw/EqIxwlEQ dCwW3klV6Jyos4MEhRo3sydDEcA3xWWG7vtHOLFx/v+tNaU8JFsn X-Gm-Gg: ASbGncsBItx++vxo+59uWE9vW3lCsJEcnVmIZnd+Icw7Goah/N+06Dcg9NQiVbwL2Oh aup2wusspySVWbL0HIQJLrtjUrhyhp+/UaC0dCv2t5HhGQEMd9V+uikcf9SlXtWpULMIjNSKlQN wbSxILpsyoxeemKSMPFoJtxWBlDIzTDbWQnyrV95M0SX5KOF0kFyiofK6ubiyekvo1bKjzBNpnE MoEOv00FHA8uX8pwzJOKV5QTjlmhdl3gjP4o1QXs6cbLsVWU5XuUTyogiq0x6Cl4cOuV0FG43v9 kTJQrEcHvROs+ucjI+BLS54ZxkTNyLKfcg== X-Google-Smtp-Source: AGHT+IE+dNgcl4E7pguNUlC5INkDyLFPgwWVu3VZRvQ/y5qejprY428/IZKbn/0G77xeDNYPHTrGtg== X-Received: by 2002:a05:600c:4713:b0:436:488f:4f3 with SMTP id 5b1f17b1804b1-438dc3cbfc9mr76466025e9.17.1738259331637; Thu, 30 Jan 2025 09:48:51 -0800 (PST) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438e244ed3fsm30858705e9.31.2025.01.30.09.48.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Jan 2025 09:48:50 -0800 (PST) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_BF79B486-22D4-4789-838C-229C17FAD47E" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.300.87.4.3\)) Subject: Re: [PHP-DEV] RFC: Marking return values as important (#[\NoDiscard]) Date: Thu, 30 Jan 2025 18:48:39 +0100 In-Reply-To: Cc: php internals To: =?utf-8?Q?Tim_D=C3=BCsterhus?= References: <3f170549-cfd6-441e-b892-cf51d726dbe8@bastelstu.be> <3b4d9be8-9255-44ab-95c5-ea3045212cf4@app.fastmail.com> X-Mailer: Apple Mail (2.3826.300.87.4.3) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_BF79B486-22D4-4789-838C-229C17FAD47E Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 30 janv. 2025 =C3=A0 16:51, Tim D=C3=BCsterhus a = =C3=A9crit : >=20 > Hi >=20 > Am 2025-01-30 10:02, schrieb Rowan Tommins [IMSoP]: >> I think it would be good to explore alternatives - for instance, I = think C# has a reserved _ variable to assign discarded results to, but = may be misremembering. >=20 > A quick search confirms that C# supports the `_` variable. It's also = supported with Rust. >=20 > We are open to possible alternatives to the `(void)` cast, this was = also something we discussed while drafting the RFC. However we opted for = the `(void)` with out proposal for the following reasons: >=20 > - `$_ =3D func();` is already working as a regular variable (see my = reply to Rob regarding lifetimes), thus repurposing it as a =E2=80=9Cdisca= rd pile=E2=80=9D would cause backwards compatibility issues. > - `_ =3D func();` would introduce new syntax (just like `(void)`), but = does not look and feel like PHP to us. > - `(void)func();` has precedent in other languages (just like `_ =3D`) = and looks and feels like PHP. In fact in earlier PHP versions there = already was an `(unset)` cast to unconditionally turn an expression into = `null`. We opted for `(void)` instead of bringing back `(unset)` for the = following reasons: (1) Possible confusion about a deprecated + removed = feature coming back (e.g. avoiding old blog articles). (2) More cleanly = enforcing that `(void)` is a statement, rather than an expression. (3) = The similarity with the `void` return type to indicate that = =E2=80=9Cnothing=E2=80=9D is returned. A possible alternative is: `! func();`, that already =E2=80=9Cworks=E2=80=9D= as of today, modulo possible optimisation. In any case, I think that `(void) func();` is not self-explanatory, and = in the event I want to ignore a result I am not supposed to ignore, I = will probably write something more explicit like, `$unused =3D = func();`(possibly decorated with an annotation telling static analysers = not to complain that $unused is unused), or `forget(func())` BTW, the RFC says that introducing the `(void)` cast is a backward = compatible change, which is incorrect; see: https://3v4l.org/iN7OY =E2=80=94Claude --Apple-Mail=_BF79B486-22D4-4789-838C-229C17FAD47E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 30 janv. 2025 =C3=A0 16:51, Tim D=C3=BCsterhus = <tim@bastelstu.be> a =C3=A9crit :

Hi

Am 2025-01-30 = 10:02, schrieb Rowan Tommins [IMSoP]:
I = think it would be good to explore alternatives - for instance, I think = C# has a reserved _ variable to assign discarded results to, but may be = misremembering.

A quick search confirms that C# = supports the `_` variable. It's also supported with Rust.

We are = open to possible alternatives to the `(void)` cast, this was also = something we discussed while drafting the RFC. However we opted for the = `(void)` with out proposal for the following reasons:

- `$_ =3D = func();` is already working as a regular variable (see my reply to Rob = regarding lifetimes), thus repurposing it as a =E2=80=9Cdiscard pile=E2=80= =9D would cause backwards compatibility issues.
- `_ =3D func();` = would introduce new syntax (just like `(void)`), but does not look and = feel like PHP to us.
- `(void)func();` has precedent in other = languages (just like `_ =3D`) and looks and feels like PHP. In fact in = earlier PHP versions there already was an `(unset)` cast to = unconditionally turn an expression into `null`. We opted for `(void)` = instead of bringing back `(unset)` for the following reasons: (1) = Possible confusion about a deprecated + removed feature coming back = (e.g. avoiding old blog articles). (2) More cleanly enforcing that = `(void)` is a statement, rather than an expression. (3) The similarity = with the `void` return type to indicate that =E2=80=9Cnothing=E2=80=9D = is returned.

A possible = alternative is: `! func();`, that already =E2=80=9Cworks=E2=80=9D as of = today, modulo possible optimisation.

In any = case, I think that `(void) func();` is not self-explanatory, and in the = event I want to ignore a result I am not supposed to ignore, I will = probably write something more explicit like, `$unused =3D = func();`(possibly decorated with an annotation telling static analysers = not to complain that $unused is unused), or = `forget(func())`

BTW,  the RFC says that = introducing the `(void)` cast is a backward compatible change, which is = incorrect; see: https://3v4l.org/iN7OY

<= /div>
=E2=80=94Claude

= --Apple-Mail=_BF79B486-22D4-4789-838C-229C17FAD47E--