ctor_promotion_defaults.phpt 599 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. --TEST--
  2. Constructor promotion with default values
  3. --FILE--
  4. <?php
  5. class Point {
  6. public function __construct(
  7. public float $x = 0.0,
  8. public float $y = 1.0,
  9. public float $z = 2.0
  10. ) {}
  11. }
  12. var_dump(new Point(10.0));
  13. var_dump(new Point(10.0, 11.0));
  14. var_dump(new Point(10.0, 11.0, 12.0));
  15. ?>
  16. --EXPECT--
  17. object(Point)#1 (3) {
  18. ["x"]=>
  19. float(10)
  20. ["y"]=>
  21. float(1)
  22. ["z"]=>
  23. float(2)
  24. }
  25. object(Point)#1 (3) {
  26. ["x"]=>
  27. float(10)
  28. ["y"]=>
  29. float(11)
  30. ["z"]=>
  31. float(2)
  32. }
  33. object(Point)#1 (3) {
  34. ["x"]=>
  35. float(10)
  36. ["y"]=>
  37. float(11)
  38. ["z"]=>
  39. float(12)
  40. }