On Tue, Jul 6, 2021 at 12:58 PM Rowan Tommins <rowan.coll...@gmail.com> wrote:
> On 06/07/2021 11:31, Benjamin Eberlei wrote: > > This is not 100% correct, you can have an attribte #[Foo(Foo::class)] and > > then calling ReflectionAttribute::getArguments would also require to > > resolve the type Foo. So this is not different than what could happen > right > > now already. > > > Despite its name, "::class" doesn't care about class definitions, it > just performs a string substitution based on the "namespace" and "use" > statements in the current file. > > In most cases, that happens entirely at compile time, so the following > two source files compile identically: > Hah, I realized after sending the example was bad :) I should have used an example using actual constants (vs magic ones): #[Foo(Foo::BAR)] This would trigger autoloading and resolving during getArguments() > > Short form: > > namespace Somebody\Something; > #[ Foo( Foo::class ) ] > class Whatever {} > > Expanded form: > > namespace Somebody\Something; > #[ \Somebody\Something\Foo( '\Somebody\Something\Foo' ) ] > class Whatever {} > > > There is no need for the class \Somebody\Something\Foo to actually exist > in either case, the argument is just a string: > https://3v4l.org/bgNa2#v8.0.8 > > > Regards, > > -- > Rowan Tommins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >