Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Last active September 6, 2020 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/8c1b6451c27e6ae90294fa973e9e6254 to your computer and use it in GitHub Desktop.
Save shin1x1/8c1b6451c27e6ae90294fa973e9e6254 to your computer and use it in GitHub Desktop.
<?php
namespace Acme;
@@Attribute
final class Attr1 {}
@@Attr1
final class Foo {}
$reflectionClass = new \ReflectionClass(Foo::class);
$attributes = $reflectionClass->getAttributes();
var_dump($attributes[0]->newInstance());
/*
Fatal error: Uncaught Error: Attempting to use non-attribute class "Acme\Attr1" as attribute in /app/attr.php:13
Stack trace:
#0 /app/attr.php(13): ReflectionAttribute->newInstance()
#1 {main}
thrown in /app/attr.php on line 13
*/
<?php
namespace Acme;
@@Attribute
final class Attr1 {}
@@Attr10
final class Foo {}
$reflectionClass = new \ReflectionClass(Foo::class);
$attributes = $reflectionClass->getAttributes();
var_dump($attributes[0]->newInstance());
/*
Fatal error: Uncaught Error: Attribute class "Acme\Attr10" not found in /app/attr.php:13
Stack trace:
#0 /app/attr.php(13): ReflectionAttribute->newInstance()
#1 {main}
thrown in /app/attr.php on line 13
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment