Skip to content

Commit fc6f3d1

Browse files
committed
Add test for getClass() error conditions
Inspired by phpGH-7372, to show that these are not dead code.
1 parent ea604f0 commit fc6f3d1

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
--TEST--
2+
Using invalid self/parent types in closure
3+
--FILE--
4+
<?php
5+
6+
$fn1 = function(self $x) {};
7+
try {
8+
(new ReflectionFunction($fn1))->getParameters()[0]->getClass();
9+
} catch (ReflectionException $e) {
10+
echo $e->getMessage(), "\n";
11+
}
12+
13+
$fn2 = function(parent $x) {};
14+
try {
15+
(new ReflectionFunction($fn2))->getParameters()[0]->getClass();
16+
} catch (ReflectionException $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
class Test {}
21+
$fn3 = (function(parent $x) {})->bindTo(new Test, Test::class);
22+
try {
23+
(new ReflectionFunction($fn3))->getParameters()[0]->getClass();
24+
} catch (ReflectionException $e) {
25+
echo $e->getMessage(), "\n";
26+
}
27+
28+
?>
29+
--EXPECTF--
30+
Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d
31+
Parameter uses "self" as type but function is not a class member
32+
33+
Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d
34+
Parameter uses "parent" as type but function is not a class member
35+
36+
Deprecated: Method ReflectionParameter::getClass() is deprecated in %s on line %d
37+
Parameter uses "parent" as type although class does not have a parent

0 commit comments

Comments
 (0)