PhpDeprecationDetector icon indicating copy to clipboard operation
PhpDeprecationDetector copied to clipboard

False positives for array functions

Open Stadly opened this issue 1 year ago • 2 comments

$a = [1,2,3];
key($a);
reset($a);
end($a);

The above code falsely produces errors:

Function key() is removed.
Consider replace with use with objects is deprecated()

Function reset() is removed.
Consider replace with use with objects is deprecated()

Function end() is removed.
Consider replace with use with objects is deprecated()

There may be other similar functions producing this error as well. These are the ones I had in my code base.

Stadly avatar Sep 22 '23 12:09 Stadly

This is from PHP 8.1, and it's a strange one, because it's only deprecated if an object, rather than an array is supplied. But this tool doesn't know what you're feeding it. I think it's worth checking that you're only supplying arrays to these functions. Then there's an option to --skip-checks, so you can use something like: phpdd scan --skip-checks reset,end PATH

sharpchi avatar Nov 09 '23 12:11 sharpchi

We got this too when using current().

I think the problem is the wording from the tool: 'Function XXXX() is removed'. The function is not removed from PHP. The function isnt even deprecated as a whole - only a specific use case is deprecated. This should be a warning and not an error outright.

Then the second line "Consider replace with use with objects is deprecated()" is not gramatically correct so reading it several times over is still confusing as to what its telling the user to do. I believe the intent was to say that the 'use with objects is deprecated' as an note/warning, but instead its being presented as a replacement consideration.

The main line should be replaced with something like 'Function XXX() use with objects is deprecated.'

codewise-nicolas avatar Feb 15 '24 18:02 codewise-nicolas