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

From: Date: Thu, 13 Feb 2025 14:17:07 +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 [email protected] to get a copy of this message
Hi

Am 2025-02-13 09:49, schrieb Eugene Sidelnyk:
I'm just wondering how the new attribute that defines behavior (not just additional metadata) will fit into the rest of the system.
See my reply to Jakob: There are already several attributes that define behavior.
Do you think it's reasonable to implement "non-discardability of the returned value" as the attribute? Maybe new keyword would be better solution?
Yes, we believe that implementing this as an attribute rather than a keyword is the right choice and the reasoning is similar to the #[\Override] attribute that was added in PHP 8.3: https://wiki.php.net/rfc/marking_overriden_methods#why_an_attribute_and_not_a_keyword With the exception of error handlers, applying (or unapplying) the #[\NoDiscard] attribute will not affect how a PHP program works. It will just emit a new warning which when suppressed, will not affect the program’s behavior at all. This is different to return types, which are relevant due to the Liskov substitution principle and where changing the return type would actually result in a breaking change to the program’s public API. Best regards Tim Düsterhus

Thread (48 messages)

« previous php.internals (#126391) next »