phpmd
phpmd copied to clipboard
False positive for UnusedPrivateMethod when method is used as callable
- PHPMD version: latest
- PHP Version: 7.4
- Installation type: composer
- Operating System / Distribution & Version: Linux
Example
Having
usort($history, [__CLASS__, '_sortHistoryByTimestamp']);
and
private static function _sortHistoryByTimestamp($a, $b)
{
// ...
}
Duplicates #253 but the old one get closed so let's keep this one open.
I wonder if we will support all the syntax (i.e. __CLASS__, self::class, static::class, get_class() etc.).
I see that the next version of your project will bump PHP version to 8.2.
Since PHP 8.1, it's possible to write:
usort($history, self::_sortHistoryByTimestamp(...));
And this should be supported by PHPMD if I'm not mistaken.
I see that the next version of your project will bump PHP version to 8.2.
We will support 7.4 for the next time. ;)
I wonder if we will support all the syntax (i.e. CLASS, self::class, static::class, get_class() etc.).
Dont know if is_callable() works.
(May take a look at phpstan ... it does not report the method as unused)
Yes yes, we know PHPMD has a bug, or rather that we never implemented any support for those syntax, we have the same issue with [$this, 'foo'] and is_callable is indeed a runtime way to know if something is callable, but that's not the end of it because:
we need a static way and most importantly we need to know what is expecting a callable.
I.E.
usort([__CLASS__, 'a'], [__CLASS__, 'b']);
array_map([__CLASS__, 'c'], [__CLASS__, 'd']);
In this example: b() and c() are used, a() and d() are unused.