1.2.1282. Untyped No Default Properties¶
This rule reports untyped properties without default value, that are not assigned at constructor time.
This means that these properties will be assigned later, and are now running the risk to be accessed before being written. This yields a warning, and, when the property get typed, event with mixed
, a fatal error.
<?php
class x {
public $noTypeNoDefaultNoConstructor;
public $noTypeNoDefaultButConstructor;
function __construct() {
// property is defined in the constructor, so always defined
$this->noTypeNoDefaultButConstructor = 1;
}
function foo() {
// possible error here
return $this->noTypeNoDefaultNoConstructor;
}
}
?>
1.2.1282.1. Specs¶
Short name |
Classes/UntypedNoDefaultProperties |
Rulesets |
|
Exakat since |
2.6.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Features |
property |
Available in |