mirror of
https://github.com/php/php-src.git
synced 2024-09-21 18:07:23 +00:00
064b464448
RFC: https://wiki.php.net/rfc/constructor_promotion Closes GH-5291.
22 lines
392 B
PHP
22 lines
392 B
PHP
--TEST--
|
|
Constructor promotion (basic example)
|
|
--FILE--
|
|
<?php
|
|
|
|
class Point {
|
|
public function __construct(public int $x, public int $y, public int $z) {}
|
|
}
|
|
|
|
$point = new Point(1, 2, 3);
|
|
|
|
// Check that properties really are typed.
|
|
try {
|
|
$point->x = "foo";
|
|
} catch (TypeError $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
Cannot assign string to property Point::$x of type int
|