Skip to content

reflection: Deprecate Reflection*::setAccessible() #19273

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 2 additions & 0 deletions ext/reflection/php_reflection.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ public function getPrototype(): ReflectionMethod {}
public function hasPrototype(): bool {}

/** @tentative-return-type */
#[\Deprecated(since: '8.5', message: "as it has no effect")]
public function setAccessible(bool $accessible): void {}
}

Expand Down Expand Up @@ -542,6 +543,7 @@ public function getDeclaringClass(): ReflectionClass {}
public function getDocComment(): string|false {}

/** @tentative-return-type */
#[\Deprecated(since: '8.5', message: "as it has no effect")]
public function setAccessible(bool $accessible): void {}

/** @tentative-return-type */
Expand Down
22 changes: 19 additions & 3 deletions ext/reflection/php_reflection_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion ext/reflection/tests/ReflectionMethod_setAccessible.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $protected->invokeArgs(new A, array(NULL));
$protectedStatic->invoke(NULL, NULL);
$protectedStatic->invokeArgs(NULL, array(NULL));
?>
--EXPECT--
--EXPECTF--
A::aPrivate
A::aPrivate
A::aPrivateStatic
Expand All @@ -46,6 +46,14 @@ A::aProtected
A::aProtected
A::aProtectedStatic
A::aProtectedStatic

Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
A::aPrivate
A::aPrivate
A::aPrivateStatic
Expand Down
14 changes: 14 additions & 0 deletions ext/reflection/tests/ReflectionProperty_setAccessible.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ string(1) "e"
string(1) "f"
string(1) "g"
string(1) "h"

Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
string(1) "e"
string(1) "f"
string(1) "g"
Expand All @@ -111,6 +119,12 @@ string(1) "c"
string(1) "e"
string(1) "f"
string(1) "g"

Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d

Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
string(1) "e"
string(1) "f"
string(1) "g"
Expand Down
1 change: 0 additions & 1 deletion ext/reflection/tests/bug79683.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ $b = new B();

$reflector = new ReflectionClass($b);
$property = $reflector->getProperty('prop2');
$property->setAccessible(true);
$property->setValue($b, new A());

var_dump($b);
Expand Down
1 change: 0 additions & 1 deletion ext/reflection/tests/property_hooks/basics.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ try {
} catch (ReflectionException $e) {
echo $e->getMessage(), "\n";
}
$s->setAccessible(true);
$s->invoke($test, 42);
var_dump($test->prop2);
dumpFlags($rp2);
Expand Down
8 changes: 4 additions & 4 deletions ext/zend_test/tests/gh9871.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class A {
}

$property = new MyReflectionProperty('A', 'protected');
$property->setAccessible(true);
$property->isStatic();

?>
--EXPECTF--
Expand All @@ -28,7 +28,7 @@ $property->setAccessible(true);
<!-- init ReflectionProperty::__construct() -->
<ReflectionProperty::__construct>
</ReflectionProperty::__construct:NULL>
<!-- init ReflectionProperty::setAccessible() -->
<ReflectionProperty::setAccessible>
</ReflectionProperty::setAccessible:NULL>
<!-- init ReflectionProperty::isStatic() -->
<ReflectionProperty::isStatic>
</ReflectionProperty::isStatic:false>
</file '%s'>