1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 10:57:08 +01:00
psalm/docs/running_psalm/issues/AssignmentToVoid.md

26 lines
515 B
Markdown
Raw Normal View History

2020-03-19 17:32:49 +01:00
# AssignmentToVoid
Emitted when assigning from a function that returns `void`:
```php
2020-03-21 00:13:46 +01:00
<?php
2020-03-19 17:32:49 +01:00
function foo() : void {}
$a = foo();
```
2020-03-21 14:48:35 +01:00
## 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.
2020-03-21 14:48:35 +01:00
2020-03-19 17:42:41 +01:00
## How to fix
2020-03-19 17:32:49 +01:00
2020-03-21 14:48:35 +01:00
You should just be able to remove the assignment entirely:
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
function foo() : void {}
foo();
```