1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-05 21:19:03 +01:00
psalm/docs/running_psalm/issues/MissingConstructor.md

23 lines
938 B
Markdown
Raw Normal View History

2020-03-19 17:32:49 +01:00
# MissingConstructor
2022-02-05 12:27:53 +01:00
Unitialized properties are statically hard to analyze. To prevent mistakes, Psalm will enforce that all properties should be initialized.
2022-02-17 20:04:25 +01:00
It does that through [PropertyNotSetInConstructor](./PropertyNotSetInConstructor.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 non-null properties without default values are defined in a class without a `__construct` method
2022-05-27 11:04:00 +02:00
If your project relies on having uninitialized properties, it is advised to suppress this issue, as well as [PropertyNotSetInConstructor](./PropertyNotSetInConstructor.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;
}
```