Skip to content

Instantly share code, notes, and snippets.

@beberlei
Created April 14, 2020 13:52
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 beberlei/6cf033a3d2cd1a8d991fcabdecce0626 to your computer and use it in GitHub Desktop.
Save beberlei/6cf033a3d2cd1a8d991fcabdecce0626 to your computer and use it in GitHub Desktop.
--TEST--
Attributes can be placed before and after docblocks
--FILE--
<?php
<<A1("before")>>
/** foo */
<<A1("after")>>
class Foo
{
<<A1(2)>>
public const FOO = 'foo', BAR = 'bar';
<<A1(3)>>
public $x, $y;
<<A1(4)>>
public function foo(<<A1(5)>> $a, <<A1(6)>> $b) { }
}
$ref = new \ReflectionClass(Foo::class);
$attributes = $ref->getAttributes();
var_dump($ref->getDocComment());
foreach ($attributes as $attribute) {
var_dump($attribute->getName(), $attribute->getArguments());
}
?>
--EXPECTF--
string(10) "/** foo */"
string(2) "A1"
array(1) {
[0]=>
string(6) "before"
}
string(2) "A1"
array(1) {
[0]=>
string(5) "after"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment