constructor_promotion.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. --TEST--
  2. Using Reflection on promoted properties
  3. --FILE--
  4. <?php
  5. class Test {
  6. public $z;
  7. public function __construct(
  8. public int $x,
  9. /** @SomeAnnotation() */
  10. public string $y = "123",
  11. string $z = "abc",
  12. ) {}
  13. }
  14. $rc = new ReflectionClass(Test::class);
  15. echo $rc, "\n";
  16. $y = $rc->getProperty('y');
  17. var_dump($y->isPromoted());
  18. var_dump($y->getDocComment());
  19. $z = $rc->getProperty('z');
  20. var_dump($z->isPromoted());
  21. echo "\n";
  22. $rp = new ReflectionParameter([Test::class, '__construct'], 'y');
  23. var_dump($rp->isPromoted());
  24. $rp = new ReflectionParameter([Test::class, '__construct'], 'z');
  25. var_dump($rp->isPromoted());
  26. ?>
  27. --EXPECTF--
  28. Class [ <user> class Test ] {
  29. @@ %s 3-11
  30. - Constants [0] {
  31. }
  32. - Static properties [0] {
  33. }
  34. - Static methods [0] {
  35. }
  36. - Properties [3] {
  37. Property [ public $z = NULL ]
  38. Property [ public int $x ]
  39. Property [ public string $y ]
  40. }
  41. - Methods [1] {
  42. Method [ <user, ctor> public method __construct ] {
  43. @@ %s 5 - 10
  44. - Parameters [3] {
  45. Parameter #0 [ <required> int $x ]
  46. Parameter #1 [ <optional> string $y = '123' ]
  47. Parameter #2 [ <optional> string $z = 'abc' ]
  48. }
  49. }
  50. }
  51. }
  52. bool(true)
  53. string(24) "/** @SomeAnnotation() */"
  54. bool(false)
  55. bool(true)
  56. bool(false)