mirror of
https://github.com/danog/psalm.git
synced 2024-12-05 21:19:03 +01:00
35 lines
742 B
Markdown
35 lines
742 B
Markdown
|
# UnsupportedReferenceUsage
|
||
|
|
||
|
Emitted when Psalm encounters a reference that it is not currently able to track (for instance a reference to an array
|
||
|
offset of an array offset: `$foo = &$bar[$baz[0]]`). When an unsupported reference is encountered, Psalm will issue this
|
||
|
warning and treat the variable as though it wasn't actually a reference.
|
||
|
|
||
|
## How to fix
|
||
|
|
||
|
This can sometimes be fixed by using a temporary variable:
|
||
|
|
||
|
```php
|
||
|
<?php
|
||
|
|
||
|
/** @var non-empty-list<int> */
|
||
|
$bar = [1, 2, 3];
|
||
|
/** @var non-empty-list<int> */
|
||
|
$baz = [1, 2, 3];
|
||
|
|
||
|
$foo = &$bar[$baz[0]];
|
||
|
```
|
||
|
|
||
|
can be turned into
|
||
|
|
||
|
```php
|
||
|
<?php
|
||
|
|
||
|
/** @var non-empty-list<int> */
|
||
|
$bar = [1, 2, 3];
|
||
|
/** @var non-empty-list<int> */
|
||
|
$baz = [1, 2, 3];
|
||
|
|
||
|
$offset = $baz[0];
|
||
|
$foo = &$bar[$offset];
|
||
|
```
|