mirror of
https://github.com/danog/psalm.git
synced 2024-12-15 02:47:02 +01:00
ea52b9d23a
While I was searching for some code, ran across these.
26 lines
515 B
Markdown
26 lines
515 B
Markdown
# AssignmentToVoid
|
|
|
|
Emitted when assigning from a function that returns `void`:
|
|
|
|
```php
|
|
<?php
|
|
|
|
function foo() : void {}
|
|
$a = foo();
|
|
```
|
|
|
|
## Why this is bad
|
|
|
|
Though `void`-returning functions are treated by PHP as returning `null` (so this on its own does not lead to runtime errors), `void` is a concept more broadly in programming languages which is not designed for assignment purposes.
|
|
|
|
## How to fix
|
|
|
|
You should just be able to remove the assignment entirely:
|
|
|
|
```php
|
|
<?php
|
|
|
|
function foo() : void {}
|
|
foo();
|
|
```
|