Re: Re: RFC: Marking return values as important (#[\NoDiscard])
| From: | Derick Rethans | Date: | Fri, 14 Feb 2025 11:57:02 +0000 |
| Subject: | Re: Re: RFC: Marking return values as important (#[\NoDiscard]) | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126406@lists.php.net to get a copy of this message | ||
On Thu, 13 Feb 2025, Tim Düsterhus wrote:
> Am 2025-02-13 09:16, schrieb Jakob Givoni:
>
> > Attributes were added as a structured replacement for docblock props
> > and I don't like it when they affect how a program actually runs (as
> > long as you're not using reflection).
>
> Excluding the
#[\Attribute] attribute, PHP currently has 5
> native
> attributes and they all affect how the program runs. The initial
> accepted Attribute RFC even lists several “behavior-affecting”
> attributes in the “Use Cases” section:
> https://wiki.php.net/rfc/attributes_v2#use_cases. It is
> probably fair
> to say that use-cases like #[\NoDiscard] do not go against the
> vision intended by the Attribute RFC.
>
> You could think of it as the PHP engine using Reflection internally to
> do something differently.
I don't agree, but for a different reason.
None of the current attributes (ReturnTypeWillChange,
AllowDynamicProperties, SensitiveParameter, Override, and Deprecated)
change the behaviour of how a program runs. They only add warnings. with
the exception of AllowDynamicProperties to be an actual 'feature' in PHP
9.0 (now it's only a deprecation warning silencer).
That's the same with this suggested NoDiscard, it doesn't change how a
program is run — it merely adds a warning.
cheers,
Derick