On Sat, Oct 31, 2020, at 5:06 AM, Rowan Tommins wrote:
> > This would be
> >an artificial limitation on attributes to patch over the inherent
> >inconsistency of the grouped syntax for nested attributes.
>
>
> There is no artificial limitation; there is a binary choice: does
> #[Foo] represent an object or a list with one item in? This is
> completely new syntax, so there is nothing for it to be inconsistent
> with other than itself.
>
> I am arguing that having it represent a list with one item in is
> actually *more* consistent, because when you attach attributes to a
> declaration, they are always retrieved as a list.
Perhaps a naive question, but I'm missing the downside of:
#[Foo(Bar(name="baz"))]
#[Attribute]
class Foo {
public function construct(public Bar $bar) {}
}
class Bar {
public function construct(public string $name) {}
}
Why is that not OK? Someone mentioned it means you couldn't call a function
there, but... that's not a huge problem because I can't imagine why you would.
If we really wanted to avoid that:
#[Foo(new Bar(name="baz"))]
That would be unambiguous, if a bit ugly.
--Larry Garfield
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php