ctor_promotion_attributes.phpt 499 B

12345678910111213141516171819202122
  1. --TEST--
  2. Attributes on promoted properties are assigned to both the property and parameter
  3. --FILE--
  4. <?php
  5. class Test {
  6. public function __construct(
  7. #[NonNegative]
  8. public int $num,
  9. ) {}
  10. }
  11. $prop = new ReflectionProperty(Test::class, 'num');
  12. var_dump($prop->getAttributes()[0]->getName());
  13. $param = new ReflectionParameter([Test::class, '__construct'], 'num');
  14. var_dump($param->getAttributes()[0]->getName());
  15. ?>
  16. --EXPECT--
  17. string(11) "NonNegative"
  18. string(11) "NonNegative"