ctor_promotion_basic.phpt 392 B

123456789101112131415161718192021
  1. --TEST--
  2. Constructor promotion (basic example)
  3. --FILE--
  4. <?php
  5. class Point {
  6. public function __construct(public int $x, public int $y, public int $z) {}
  7. }
  8. $point = new Point(1, 2, 3);
  9. // Check that properties really are typed.
  10. try {
  11. $point->x = "foo";
  12. } catch (TypeError $e) {
  13. echo $e->getMessage(), "\n";
  14. }
  15. ?>
  16. --EXPECT--
  17. Cannot assign string to property Point::$x of type int