Re: RFC: Marking return values as important (#[\NoDiscard])

From: Date: Mon, 24 Feb 2025 15:34:00 +0000
Subject: Re: RFC: Marking return values as important (#[\NoDiscard])
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Wed, Feb 12, 2025 at 10:44 PM Jorg Sowa <[email protected]> wrote:

> I must agree with Kamil. I don't see practical benefits of this feature
> that would surpass the implications it has for the language. We already
> have static analysis handling such cases and it can be extended even to
> non-pure functions. Moreover, syntax (void) adds additional complexity to
> beginners' understanding of the typing system. The second option with $_ is
> BC on the other hand, so both options are unsatisfying. And honestly, I
> don't have good ideas for it.
>
> Kind regards,
> Jorg Sowa
>

Hi Jorg,

To be clear: There is no BC break with $_. Opcache doesn't discard
variables containing objects, so there is no observable change in behavior
from what we're proposing. It doesn't change the variable semantics at all.
Or am I misunderstanding what you're referring to?

In addition, I reached out to see if Ondřej (Creator of PHPStan) had an
opinion: https://phpc.social/@OndrejMirtes/114040888791921128
- So on top
of our previous arguments that PHP shouldn't depend on 3rd party tools for
everything, there is also at least interest in having this in core from the
tool creators.

> @edorian It already exists for PHPStan as a 3rd party extension:
https://github.com/DaveLiddament/phpstan-php-language-extensions
(MustUseResult)
> Additionally, PHPStan itself reports this if you call a @phpstan-pure
method or function and not use its result.
> This attribute would be valuable for functions that aren’t pure but
you’re still supposed to read the returned value.

Kind regards,
Volker

--
Volker Dusch
Head of Engineering
Tideways GmbH
Königswinterer Str. 116
53227 Bonn
https://tideways.io/imprint

Sitz der Gesellschaft: Bonn
Geschäftsführer: Benjamin Außenhofer (geb. Eberlei)
Registergericht: Amtsgericht Bonn, HRB 22127


Thread (48 messages)

« previous php.internals (#126497) next »