vimeo/psalm

`array_splice` type and side effects not handled properly

Open

#8,202 建立於 2022年6月29日

在 GitHub 查看
 (3 留言) (0 反應) (0 負責人)PHP (668 fork)batch import
Help wantedeasy problemsenhancementgood first issue

倉庫指標

Star
 (5,369 star)
PR 合併指標
 (平均合併 3天 12小時) (30 天內合併 5 個 PR)

描述

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.

貢獻者指南