Uninitialized
A data container, such as a variable, a property, or an array index, is uninitialized, when it is used for reading, while no value was provided so far.
Different behaviors happen, depending on the type of data container.
- Variable: a warning is emitted, and the variable’s content is actually
null. The variable stays undefined - Static Property: a Fatal error is emitted
- Undefined Normal Property: a warning is emitted. The property’s content is actually
null - Untyped Normal Property without default value: the property’s content is actually
null. No warning nor error - Typed Normal Property without default value: a fatal error is emitted
- Property with default value: the default value is used.
<?php
echo $trunk; // Undefined variable $trunk
class Elephpant {
public int $trunkLength;
}
echo Elephpant::$tusk; // Access to undeclared static property Elephpant::$tusk
new Elephpant()->tusk; //
new Elephpant()->trunkLength; // Typed property Elephpant::$trunkLength must not be accessed before initialization
?>