> Am 22.05.2020 um 13:08 schrieb Nikita Popov <nikita....@gmail.com>:
> 
> On Wed, May 20, 2020 at 7:08 PM Benjamin Eberlei <kont...@beberlei.de>
> wrote:
> 
>> 2. Rename PhpAttribute to Attribute in global namespace (independent of the
>> namespace RFC)
> 
> As was mentioned in one of the previous discussions, we expect that PHP is
> going to ship more language-provided attributes in the future. With this
> proposal we have the "Attribute" attribute, but I expect we'll at least
> have "Deprecated" as well, and probably also something along the lines of
> "Jit" or "NoJit". While I'm happy with "Attribute" living in the global
> namespace, I don't really think we'd want to introduce "Jit" as a class in
> the global namespace. The name is simply to generic and does not indicate
> that this is part of the attribute system. We'd be forced to go with things
> like DeprecatedAttribute or JitAttribute, which seems rather non-optimal to
> me, as we're just reinventing namespaces to avoid using them...
> 
> As such, I would suggest to introduce a common namespace for all attributes
> provided by PHP. This means we'd have Attributes\Attribute,
> Attributes\Deprecated, Attributes\Jit, Attributes\NoJit etc. (I'm also okay
> with the PHP\Attributes\Deprecated variant, but that's a separate question).
> 
> Nikita

At that point, don't we just want to be able to generically mark all attribute 
classes visible as being an Attribute?

Also the classical examples like <<ORM\Entity("...")>> do not tell you anyhow 
that they're Attributes, if the class is accessed outside of attribute context. 
And I guess, with the logic you proposed, it will likely be named 
"ORM\Attribute\Entity" making it even longer.

I think it would be good to be able to later on just write <<Deprecated>>, 
<<JIT>> etc. without further imports, as they seem to be quite basic 
functionality. I think it should remain possible to write simple code without 
much namespace awareness.

Perhaps we should actually name attribute classes including their << and >>. 
Thus "class <<JIT>> {}" (attribute decl), "new <<JIT>>()" (custom 
instantiation), "$attribute instanceof <<JIT>>". (and, for a namespaced 
attribute "$attribute instanceof MyNamespace\<<MyAttrr>>")
The engine could quite easily support that, it's just a little parser work.

That way the whole discussion as to where to put attributes in the namespace 
hierarchy would be quite moot, for PHP itself as well as userland.

Bob

P.s.: As a caveat, on parameter types, if we expect a value being of an 
attribute class, we'd need to require a qualified name containing at least one 
backslash or import-alias there. But that's acceptable I think, it will just 
happen within some internal attribute processing code.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to