Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc about property initialization #7593

Merged
merged 2 commits into from Feb 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion docs/running_psalm/issues/MissingConstructor.md
@@ -1,6 +1,16 @@
# MissingConstructor

Emitted when non-null properties without default values are defined in a class without a `__construct` method
Unitialized properties are statically hard to analyze. To prevent mistakes, Psalm will enforce that all properties should be initialized.
orklah marked this conversation as resolved.
Show resolved Hide resolved

It does that through [PropertyNotSetInConstructor](issues/PropertyNotSetInConstructor.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](issues/RedundantPropertyInitializationCheck.md)

This issue is emitted when non-null properties without default values are defined in a class without a `__construct` method

If your project rely on having uninitialized properties, it is advised to suppress this issue, as well as [PropertyNotSetInConstructor](issues/PropertyNotSetInConstructor.md) and [RedundantPropertyInitializationCheck](issues/RedundantPropertyInitializationCheck.md).
orklah marked this conversation as resolved.
Show resolved Hide resolved

```php
<?php
Expand Down
12 changes: 11 additions & 1 deletion docs/running_psalm/issues/PropertyNotSetInConstructor.md
@@ -1,6 +1,16 @@
# PropertyNotSetInConstructor

Emitted when a non-null property without a default value is declared but not set in the class’s constructor
Unitialized properties are hard to statically analyze. To prevent mistakes, Psalm will enforce that all properties should be initialized.

It does that through [MissingConstructor](issues/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](issues/RedundantPropertyInitializationCheck.md)

This issue is emitted when a non-null property without a default value is declared but not set in the class’s constructor

If your project relies on having uninitialized properties, it is advised to suppress this issue, as well as [MissingConstructor](issues/MissingConstructor.md) and [RedundantPropertyInitializationCheck](issues/RedundantPropertyInitializationCheck.md).

```php
<?php
Expand Down
@@ -1,6 +1,16 @@
# RedundantPropertyInitializationCheck

Emitted when checking `isset()` on a non-nullable property. This issue indicate a redundant check for projects that initialize their properties in constructor.
Unitialized properties are hard to statically analyze. To prevent mistakes, Psalm will enforce that all properties should be initialized.

It does that through [PropertyNotSetInConstructor](issues/PropertyNotSetInConstructor.md) and [MissingConstructor](issues/MissingConstructor.md).

Psalm will then assume every property in the codebase is initialized.

Doing that allows it to report missing initializations as well as this issue.

This issue is emitted when checking `isset()` on a non-nullable property. Because every property is assumed to be initialized, this check is redundant

If your project relies on having uninitialized properties, it is advised to suppress this issue, as well as [PropertyNotSetInConstructor](issues/PropertyNotSetInConstructor.md) and [MissingConstructor](issues/MissingConstructor.md).

```php
<?php
Expand Down