<?php
function initialize_properties_here($object) {
$object->bar = 123;
}
class Foo
{
public int $bar;
public function __construct() {
unset($this->bar);
}
public function __get(string $name)
{
initialize_properties_here($this);
}
}
var_dump((new Foo())->bar);
Fatal error: Uncaught TypeError: Value of type null returned from Foo::__get() must be compatible with unset property Foo::$bar of type int in /in/bsHXH:19
Stack trace:
#0 {main}
thrown in /in/bsHXH on line 19
Process exited with code 255.
Fatal error: Uncaught TypeError: Cannot assign null to property Foo::$bar of type int in /in/bsHXH:19
Stack trace:
#0 {main}
thrown in /in/bsHXH on line 19
Process exited with code 255.
Output for 7.4.3 - 7.4.33
Fatal error: Uncaught TypeError: Typed property Foo::$bar must be int, null used in /in/bsHXH:19
Stack trace:
#0 {main}
thrown in /in/bsHXH on line 19
Process exited with code 255.
Parse error: syntax error, unexpected 'int' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in /in/bsHXH on line 9
Process exited with code 255.
Parse error: syntax error, unexpected T_STRING, expecting T_VARIABLE in /in/bsHXH on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_STRING, expecting T_VARIABLE in /in/bsHXH on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/bsHXH on line 9
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/bsHXH on line 9
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/bsHXH on line 9
Process exited with code 255.