Skip to content

Commit

Permalink
refactor: Reflection*::setAccessible() is now no-op in PHP 8.1 (#9331)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan authored Dec 19, 2024
1 parent ab5536f commit 8fa419f
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 11 deletions.
2 changes: 0 additions & 2 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1799,8 +1799,6 @@ protected function objectToRawArray($object, bool $onlyChanged = true, bool $rec
// Loop over each property,
// saving the name/value in a new array we can return.
foreach ($props as $prop) {
// Must make protected values accessible.
$prop->setAccessible(true);
$properties[$prop->getName()] = $prop->getValue($object);
}
}
Expand Down
8 changes: 2 additions & 6 deletions system/Test/ReflectionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ trait ReflectionHelper
public static function getPrivateMethodInvoker($obj, $method)
{
$refMethod = new ReflectionMethod($obj, $method);
$refMethod->setAccessible(true);
$obj = (gettype($obj) === 'object') ? $obj : null;
$obj = (gettype($obj) === 'object') ? $obj : null;

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

$refProperty = $refClass->getProperty($property);
$refProperty->setAccessible(true);

return $refProperty;
return $refClass->getProperty($property);
}

/**
Expand Down
1 change: 0 additions & 1 deletion system/Traits/PropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ final public function getNonPublicProperties(): array
continue;
}

$property->setAccessible(true);
$properties[] = $property;
}

Expand Down
2 changes: 0 additions & 2 deletions tests/system/CLI/CLITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,11 @@ public function testParseCommandMultipleOptions(): void
public function testWindow(): void
{
$height = new ReflectionProperty(CLI::class, 'height');
$height->setAccessible(true);
$height->setValue(null, null);

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

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

$this->assertIsInt(CLI::getWidth());
Expand Down

0 comments on commit 8fa419f

Please sign in to comment.