Hi

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.

3. Naming of the attribute: I think the most precise name (if I understand
the purpose correctly) is: #[ReturnValueMayContainCriticalInformation]

Yes. Or perhaps `#[\ReturnValueImportant]` as used by the RFC title to keep it a little more succinct.

If we scale it back to mean "Look, this function may not behave the way
you'd expect it to, - the return value may actually contain some
information you might be interested in, so you better check it man", then I
think it could be a small but useful addition.

Let me refer to the “Recommended Usage” section of the RFC: https://wiki.php.net/rfc/marking_return_value_as_important#recommended_usage

My rule of thumb would be that if you have trouble writing a good custom explanation in the attribute, then it's likely not a good fit.

Best regards
Tim Düsterhus

Reply via email to