1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-03 18:17:55 +01:00
psalm/docs/running_psalm/issues/PropertyNotSetInConstructor.md

25 lines
951 B
Markdown
Raw Normal View History

2020-03-19 17:32:49 +01:00
# PropertyNotSetInConstructor
2022-10-19 20:36:43 +02:00
Uninitialized 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 classs 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() {}
}
```