Re: RFC: Marking return values as important (#[\NoDiscard])
| From: | Tim Düsterhus | Date: | Wed, 29 Jan 2025 19:50:19 +0000 |
| Subject: | Re: RFC: Marking return values as important (#[\NoDiscard]) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126234@lists.php.net to get a copy of this message | ||
Hi
On 1/29/25 20:31, Rob Landers wrote:
This looks promising! Why do we need the (void) cast? Wouldn't "@" work and avoid a BC issue?The
@ operator also suppresses any other warning or notice within the call chain. That is likely undesirable because it might hide issues one is interested in. See this example (https://3v4l.org/NDtR7):
<?php
function inner() {
var_dump($undefined);
}
function outer() {
inner();
}
outer();
outer();
@outer();
The (void) cast makes the intent of not being interested in the return value clear. In C casting to (void) is an established pattern of "using" a value that the compiler would otherwise consider unused. Likewise will the void operator suppress the TypeScript-ESLint warning of not using returned Promise: https://typescript-eslint.io/rules/no-floating-promises/#ignorevoid
Best regards
Tim Düsterhus