1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-11 16:59:45 +01:00
psalm/docs/running_psalm/issues/AssignmentToVoid.md
2020-03-21 09:48:35 -04:00

26 lines
516 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.

# 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 doesnt 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();
```