Skip to content

Commit fc04a6e

Browse files
committed
Throw when calling ReflectionAttribute::__construct()
ReflectionAttribute::__construct() accepted any number of parameters until now, because parameter validation was missing. Even though this was unlikely to be an issue in practice (since the method is private), the problem is fixed by always throwing an exception.
1 parent ef5478b commit fc04a6e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

ext/reflection/php_reflection.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6395,6 +6395,7 @@ ZEND_METHOD(ReflectionReference, getId)
63956395

63966396
ZEND_METHOD(ReflectionAttribute, __construct)
63976397
{
6398+
_DO_THROW("Cannot directly instantiate ReflectionAttribute");
63986399
}
63996400

64006401
ZEND_METHOD(ReflectionAttribute, __clone)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
ReflectionAttribute cannot be instantiated directly
3+
--FILE--
4+
<?php
5+
#[Attribute]
6+
class A {}
7+
8+
class Foo {
9+
#[A]
10+
public function bar() {}
11+
}
12+
13+
$rm = new ReflectionMethod(Foo::class, "bar");
14+
$attribute = $rm->getAttributes()[0];
15+
16+
$rm = new ReflectionMethod($attribute, "__construct");
17+
18+
try {
19+
var_dump($rm->invoke($attribute, 0, 1, 2));
20+
} catch (ReflectionException $exception) {
21+
echo $exception->getMessage();
22+
}
23+
?>
24+
--EXPECT--
25+
Cannot directly instantiate ReflectionAttribute

0 commit comments

Comments
 (0)