vimeo/psalm

array_unique 2nd parameter may restrict the array items type

Open

#7,956 建立於 2022年5月13日

在 GitHub 查看
 (11 留言) (0 反應) (0 負責人)PHP (668 fork)batch import
Help wantedeasy problemsinternal stubs/callmap

倉庫指標

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

描述

Hi,

the array_unique() function has an optional 2nd parameter flag, which is one of the following value:

  • SORT_REGULAR
  • SORT_NUMERIC
  • SORT_STRING (default value)
  • SORT_LOCALE_STRING

if the flag is one of SORT_LOCALE or SORT_LOCALE_STRING, the array should only contain strings or values that can be casted to string. I'm not sure exactly what the definition should be, maybe: int|float|string|bool|\Stringable|null

Here we can see it fail : https://3v4l.org/lJsCp

and here we can see that Psalm does not find any error: https://psalm.dev/r/2135f5de25


edit: I realized that the SORT_NUMERIC also restrict the item type, probably something like int|float|string|null

貢獻者指南