Skip to content

Commit 8fa419f

Browse files
authored
refactor: Reflection*::setAccessible() is now no-op in PHP 8.1 (#9331)
1 parent ab5536f commit 8fa419f

File tree

4 files changed

+2
-11
lines changed

4 files changed

+2
-11
lines changed

system/BaseModel.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,8 +1799,6 @@ protected function objectToRawArray($object, bool $onlyChanged = true, bool $rec
17991799
// Loop over each property,
18001800
// saving the name/value in a new array we can return.
18011801
foreach ($props as $prop) {
1802-
// Must make protected values accessible.
1803-
$prop->setAccessible(true);
18041802
$properties[$prop->getName()] = $prop->getValue($object);
18051803
}
18061804
}

system/Test/ReflectionHelper.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ trait ReflectionHelper
3939
public static function getPrivateMethodInvoker($obj, $method)
4040
{
4141
$refMethod = new ReflectionMethod($obj, $method);
42-
$refMethod->setAccessible(true);
43-
$obj = (gettype($obj) === 'object') ? $obj : null;
42+
$obj = (gettype($obj) === 'object') ? $obj : null;
4443

4544
return static fn (...$args) => $refMethod->invokeArgs($obj, $args);
4645
}
@@ -59,10 +58,7 @@ private static function getAccessibleRefProperty($obj, $property)
5958
{
6059
$refClass = is_object($obj) ? new ReflectionObject($obj) : new ReflectionClass($obj);
6160

62-
$refProperty = $refClass->getProperty($property);
63-
$refProperty->setAccessible(true);
64-
65-
return $refProperty;
61+
return $refClass->getProperty($property);
6662
}
6763

6864
/**

system/Traits/PropertiesTrait.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ final public function getNonPublicProperties(): array
7171
continue;
7272
}
7373

74-
$property->setAccessible(true);
7574
$properties[] = $property;
7675
}
7776

tests/system/CLI/CLITest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,11 @@ public function testParseCommandMultipleOptions(): void
549549
public function testWindow(): void
550550
{
551551
$height = new ReflectionProperty(CLI::class, 'height');
552-
$height->setAccessible(true);
553552
$height->setValue(null, null);
554553

555554
$this->assertIsInt(CLI::getHeight());
556555

557556
$width = new ReflectionProperty(CLI::class, 'width');
558-
$width->setAccessible(true);
559557
$width->setValue(null, null);
560558

561559
$this->assertIsInt(CLI::getWidth());

0 commit comments

Comments
 (0)