1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-05 21:19:03 +01:00
psalm/docs/running_psalm/issues/MixedAssignment.md
2022-09-15 19:38:51 +02:00

39 lines
506 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.

# MixedAssignment
Emitted when assigning an unannotated variable to a value for which Psalm
cannot infer a type more specific than `mixed`.
```php
<?php
$a = $GLOBALS['foo'];
```
## How to fix
The above example can be fixed in a few ways by adding an `assert` call:
```php
<?php
$a = $GLOBALS['foo'];
assert(is_string($a));
```
or by adding an explicit cast:
```php
<?php
$a = (string) $GLOBALS['foo'];
```
or by adding a docblock
```php
<?php
/** @var string */
$a = $GLOBALS['foo'];
```