Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Reflection*::setAccessible() is now no-op in PHP 8.1 #9331

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading