psalm icon indicating copy to clipboard operation
psalm copied to clipboard

False positive UnusedMethodCall for ReflectionProperty::setAccessible

Open zerkms opened this issue 1 year ago • 3 comments

https://psalm.dev/r/14e6e58931

zerkms avatar Aug 06 '24 22:08 zerkms

I found these snippets:

https://psalm.dev/r/14e6e58931
<?php

$conn = new \stdClass();

$connReflection = new ReflectionClass($conn);
$ioProperty = $connReflection->getProperty('foo');
$ioProperty->setAccessible(true);
Psalm output (using commit 16b24bd):

ERROR: UnusedMethodCall - 7:14 - The call to ReflectionProperty::setAccessible is not used

psalm-github-bot[bot] avatar Aug 06 '24 22:08 psalm-github-bot[bot]

Maybe it is because it is no longer necessary to call setAccessible.

Note: As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default.

https://www.php.net/manual/en/reflectionproperty.setaccessible.php

M393 avatar Aug 07 '24 08:08 M393

@M393 oh wow, didn't know that. In that case it possibly would be a room to improve the error message?

zerkms avatar Aug 07 '24 21:08 zerkms