Re: List of attributes
| From: | Larry Garfield | Date: | Sun, 01 Nov 2020 00:38:33 +0000 |
| Subject: | Re: List of attributes | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-112158@lists.php.net to get a copy of this message | ||
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