Skip to content

Commit ed2cde1

Browse files
committed
Mark Reflection(Method|Property)#setAccessible() as pure starting from PHP 8.1 onwards
This will highlight unused code. Ref: php/php-src#5412 Ref: https://wiki.php.net/rfc/make-reflection-setaccessible-no-op Ref: php/php-src#5411 Example https://3v4l.org/PNeeZ ```php <?php class Foo { private $bar = 'baz'; private function taz() { return 'waz'; } } //var_dump((new ReflectionProperty(Foo::class, 'bar'))->getValue(new Foo)); //var_dump((new ReflectionMethod(Foo::class, 'taz'))->invoke(new Foo)); ``` Produces (starting from PHP 8.1): ``` string(3) "baz" string(3) "waz" ```
1 parent 93c5df6 commit ed2cde1

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

stubs/Php81.phpstub

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@ namespace {
3131
public function isEnum(): bool {}
3232
}
3333

34+
class ReflectionProperty implements Reflector
35+
{
36+
/**
37+
* Starting from PHP 8.1, this method is pure, and has no effect.
38+
*
39+
* @psalm-pure
40+
*/
41+
public function setAccessible(bool $accessible): void {}
42+
}
43+
44+
class ReflectionMethod extends ReflectionFunctionAbstract
45+
{
46+
/**
47+
* Starting from PHP 8.1, this method is pure, and has no effect.
48+
*
49+
* @psalm-pure
50+
*/
51+
public function setAccessible(bool $accessible): void {}
52+
}
53+
3454
/** @psalm-immutable */
3555
class ReflectionEnum extends ReflectionClass implements Reflector
3656
{

0 commit comments

Comments
 (0)