Bug Report
| Subject |
Details |
| Rector version |
v0.7.26 |
| Installed as |
composer dependency |
Rector does the following change:
- array_search($needle, $haystack) !== false
+ in_array($needle, $haystack, true)
that adds , true which causes a different result e.g. for $needle = 42; $haystack = ['42'];:
(https://3v4l.org/ZM5aI)
Minimal PHP Code Causing Issue
https://getrector.org/demo/e226c0b9-4efd-4253-aac5-d87bf457e568
Expected Behaviour
Rector should do the following changes (note: each variable might also be a literal value):
- array_search($needle, $haystack) !== false
+ in_array($needle, $haystack)
- array_search($needle, $haystack, $strict) !== false
+ in_array($needle, $haystack, $strict)
and their negative counterparts:
- array_search($needle, $haystack) === false
+ !in_array($needle, $haystack)
- array_search($needle, $haystack, $strict) === false
+ !in_array($needle, $haystack, $strict)
i.e. preserve the optional third argument (https://3v4l.org/E44t1).
Moreover, it should not do this refactor for comparisons other than !== and === (e.g. != or ==) nor for values other than false (e.g. true or 0). Akin to StrposToStringsContainsRector.
References:
Bug Report
Rector does the following change:
that adds
, truewhich causes a different result e.g. for$needle = 42; $haystack = ['42'];:(https://3v4l.org/ZM5aI)
Minimal PHP Code Causing Issue
https://getrector.org/demo/e226c0b9-4efd-4253-aac5-d87bf457e568
Expected Behaviour
Rector should do the following changes (note: each variable might also be a literal value):
and their negative counterparts:
i.e. preserve the optional third argument (https://3v4l.org/E44t1).
Moreover, it should not do this refactor for comparisons other than
!==and===(e.g.!=or==) nor for values other thanfalse(e.g.trueor0). Akin to StrposToStringsContainsRector.References: