On 24/11/2020 23:09, Theodore Brown wrote:
That's not necessarily the case for nested attributes. A developer may want to declare that an attribute constructor takes a single attribute with a particular type as one of its arguments.
I'm still not sure what the use case for such an attribute constructor would be. Your example with "CustomError" seemed to be abusing nested attributes as a way to get a value object into a static declaration; and all the examples I've seen of nested attributes/annotations "in the wild" are wrapping a list of attributes in some kind of container.
Moreover, re-purposing the syntax for function calls or class instantiation is likely to cause confusion, since it looks like the code is doing something other than what it actually does (and of course it would prevent ever extending constant expressions to support function calls or class instantiation).
Then maybe we should make it *be* instantiation. The example you gave earlier, of CustomError, would be just as useful outside attributes, e.g. in a property initialiser, so perhaps what we need for that use case is not nested attributes at all, but the ability to create some subset of objects ("structs"?) inside static contexts.
That can be entirely parallel to a feature that lets you wrap a list of attributes inside another attribute, and does some recursive magic with reflection to let you delay calling their constructors.
Regards, -- Rowan Tommins (né Collins) [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php