028_grouped.phpt 726 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. --TEST--
  2. Attributes can be grouped
  3. --FILE--
  4. <?php
  5. #[A1(1), A1(2), A2(3)]
  6. class Foo
  7. {
  8. }
  9. #[
  10. A1(1),
  11. A1(2),
  12. A2(3)
  13. ]
  14. function foo() {}
  15. #[A1, A1, A2]
  16. function bar() {}
  17. $sources = [
  18. new \ReflectionClass(Foo::class),
  19. new \ReflectionFunction('foo'),
  20. new \ReflectionFunction('bar'),
  21. ];
  22. foreach ($sources as $ref) {
  23. $attr = $ref->getAttributes();
  24. var_dump(get_class($ref), count($attr));
  25. foreach ($attr as $a) {
  26. printf("%s(%s)\n", $a->getName(), implode(", ", $a->getArguments()));
  27. }
  28. echo "\n";
  29. }
  30. ?>
  31. --EXPECT--
  32. string(15) "ReflectionClass"
  33. int(3)
  34. A1(1)
  35. A1(2)
  36. A2(3)
  37. string(18) "ReflectionFunction"
  38. int(3)
  39. A1(1)
  40. A1(2)
  41. A2(3)
  42. string(18) "ReflectionFunction"
  43. int(3)
  44. A1()
  45. A1()
  46. A2()