mirror of
https://github.com/php/php-src.git
synced 2024-12-02 22:34:55 +08:00
064b464448
RFC: https://wiki.php.net/rfc/constructor_promotion Closes GH-5291.
55 lines
924 B
PHP
55 lines
924 B
PHP
--TEST--
|
|
Constructor promotiong mixed with other properties, parameters and code
|
|
--FILE--
|
|
<?php
|
|
|
|
class Test {
|
|
public string $prop2;
|
|
|
|
public function __construct(public string $prop1 = "", $param2 = "") {
|
|
$this->prop2 = $prop1 . $param2;
|
|
}
|
|
}
|
|
|
|
var_dump(new Test("Foo", "Bar"));
|
|
echo "\n";
|
|
echo new ReflectionClass(Test::class), "\n";
|
|
|
|
?>
|
|
--EXPECTF--
|
|
object(Test)#1 (2) {
|
|
["prop2"]=>
|
|
string(6) "FooBar"
|
|
["prop1"]=>
|
|
string(3) "Foo"
|
|
}
|
|
|
|
Class [ <user> class Test ] {
|
|
@@ %s
|
|
|
|
- Constants [0] {
|
|
}
|
|
|
|
- Static properties [0] {
|
|
}
|
|
|
|
- Static methods [0] {
|
|
}
|
|
|
|
- Properties [2] {
|
|
Property [ public string $prop2 ]
|
|
Property [ public string $prop1 ]
|
|
}
|
|
|
|
- Methods [1] {
|
|
Method [ <user, ctor> public method __construct ] {
|
|
@@ %s
|
|
|
|
- Parameters [2] {
|
|
Parameter #0 [ <optional> string $prop1 = '' ]
|
|
Parameter #1 [ <optional> $param2 = '' ]
|
|
}
|
|
}
|
|
}
|
|
}
|