1.2.1458. Wrong Type With Default¶
The default value is not of the declared type.
For properties, this will generate an error as soon as the default value is used : this is before constructor call for properties, and when the argument is omitted for promoted properties.
For parameters, the error happens when the argument is omitted, and the default value is fetched. Otherwise, it won’t happen. This error is immediately detected when a literal value is used. It only happens when the default is a constant (class or global) or an expression, as those are only solved at execution time.
<?php
const A = 1;
class B {
private string $c = A;
}
new B;
//Cannot assign string to property B::$c of type string
?>
See also When does PHP check for Fatal error.