Skip to content

Commit b94683d

Browse files
committed
reflection: Deprecate Reflection*::setAccessible()
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_reflectionsetaccessible
1 parent ff810d5 commit b94683d

File tree

7 files changed

+48
-10
lines changed

7 files changed

+48
-10
lines changed

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public function getPrototype(): ReflectionMethod {}
226226
public function hasPrototype(): bool {}
227227

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

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

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

547549
/** @tentative-return-type */

ext/reflection/php_reflection_arginfo.h

Lines changed: 19 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/reflection/tests/ReflectionMethod_setAccessible.phpt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $protected->invokeArgs(new A, array(NULL));
3737
$protectedStatic->invoke(NULL, NULL);
3838
$protectedStatic->invokeArgs(NULL, array(NULL));
3939
?>
40-
--EXPECT--
40+
--EXPECTF--
4141
A::aPrivate
4242
A::aPrivate
4343
A::aPrivateStatic
@@ -46,6 +46,14 @@ A::aProtected
4646
A::aProtected
4747
A::aProtectedStatic
4848
A::aProtectedStatic
49+
50+
Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
51+
52+
Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
53+
54+
Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
55+
56+
Deprecated: Method ReflectionMethod::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
4957
A::aPrivate
5058
A::aPrivate
5159
A::aPrivateStatic

ext/reflection/tests/ReflectionProperty_setAccessible.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ string(1) "e"
9595
string(1) "f"
9696
string(1) "g"
9797
string(1) "h"
98+
99+
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
100+
101+
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
102+
103+
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
104+
105+
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
98106
string(1) "e"
99107
string(1) "f"
100108
string(1) "g"
@@ -111,6 +119,12 @@ string(1) "c"
111119
string(1) "e"
112120
string(1) "f"
113121
string(1) "g"
122+
123+
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
124+
125+
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
126+
127+
Deprecated: Method ReflectionProperty::setAccessible() is deprecated since 8.5, as it has no effect in %s on line %d
114128
string(1) "e"
115129
string(1) "f"
116130
string(1) "g"

ext/reflection/tests/bug79683.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ $b = new B();
2222

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

2827
var_dump($b);

ext/reflection/tests/property_hooks/basics.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ try {
4747
} catch (ReflectionException $e) {
4848
echo $e->getMessage(), "\n";
4949
}
50-
$s->setAccessible(true);
5150
$s->invoke($test, 42);
5251
var_dump($test->prop2);
5352
dumpFlags($rp2);

ext/zend_test/tests/gh9871.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class A {
1919
}
2020

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

2424
?>
2525
--EXPECTF--
@@ -28,7 +28,7 @@ $property->setAccessible(true);
2828
<!-- init ReflectionProperty::__construct() -->
2929
<ReflectionProperty::__construct>
3030
</ReflectionProperty::__construct:NULL>
31-
<!-- init ReflectionProperty::setAccessible() -->
32-
<ReflectionProperty::setAccessible>
33-
</ReflectionProperty::setAccessible:NULL>
31+
<!-- init ReflectionProperty::isStatic() -->
32+
<ReflectionProperty::isStatic>
33+
</ReflectionProperty::isStatic:false>
3434
</file '%s'>

0 commit comments

Comments
 (0)