vimeo/psalm

`array_splice` type and side effects not handled properly

Open

#8202 aperta il 29 giu 2022

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)PHP (668 fork)batch import
Help wantedeasy problemsenhancementgood first issue

Metriche repository

Star
 (5369 star)
Metriche merge PR
 (Merge medio 3g 12h) (5 PR mergiate in 30 g)

Descrizione

I recently updated to 5.0.0-beta1 for a PHP 8.1-based project, and now I'm getting an error reported with array_splice().

https://psalm.dev/r/367fd63316

I'm having PHP take a chunk of items off an array in C code, so it takes fewer interpreter steps to get the work done. But Psalm doesn't seem to realize that the return value from splice matches the input type (including preserving string keys), or that the splice changes the array it is given.

Building the equivalent with a for-loop and array_shift() is accepted, or else there is an error in my own understanding.

I'm unsure when I last checked this exact code in Psalm 4.x. The exact version I'm using reports itself as Psalm 5.0.0-beta1@f960d71b7e8dccb0815bce28a22a33ce5410e361.

Guida contributor