2020-03-19 17:32:49 +01:00
# PropertyNotSetInConstructor
2022-02-05 23:49:27 +01:00
Unitialized properties are hard to statically analyze. To prevent mistakes, Psalm will enforce that all properties should be initialized.
2022-02-05 12:27:53 +01:00
2022-02-17 20:04:25 +01:00
It does that through [MissingConstructor ](./MissingConstructor.md ) and this issue.
2022-02-05 12:27:53 +01:00
Psalm will then assume every property in the codebase is initialized.
2022-02-17 20:04:25 +01:00
Doing that allows it to report missing initializations as well as [RedundantPropertyInitializationCheck ](./RedundantPropertyInitializationCheck.md )
2022-02-05 12:27:53 +01:00
This issue is emitted when a non-null property without a default value is declared but not set in the class’ s constructor
2022-02-17 20:04:25 +01:00
If your project relies on having uninitialized properties, it is advised to suppress this issue, as well as [MissingConstructor ](./MissingConstructor.md ) and [RedundantPropertyInitializationCheck ](./RedundantPropertyInitializationCheck.md ).
2020-03-19 17:32:49 +01:00
```php
2020-03-21 00:13:46 +01:00
< ?php
2020-03-19 17:32:49 +01:00
class A {
/** @var string */
public $foo;
public function __construct() {}
}
```