1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 02:27:59 +01:00
psalm/docs/running_psalm/issues/PropertyNotSetInConstructor.md
2022-10-19 14:36:43 -04:00

25 lines
951 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# PropertyNotSetInConstructor
Uninitialized properties are hard to statically analyze. To prevent mistakes, Psalm will enforce that all properties should be initialized.
It does that through [MissingConstructor](./MissingConstructor.md) and this issue.
Psalm will then assume every property in the codebase is initialized.
Doing that allows it to report missing initializations as well as [RedundantPropertyInitializationCheck](./RedundantPropertyInitializationCheck.md)
This issue is emitted when a non-null property without a default value is declared but not set in the classs constructor
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).
```php
<?php
class A {
/** @var string */
public $foo;
public function __construct() {}
}
```