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.
This commit is contained in:
Máté Kocsis 2022-05-03 21:21:36 +02:00
parent ef5478b823
commit fc04a6ebdd
No known key found for this signature in database
GPG key ID: FD055E41728BF310
2 changed files with 26 additions and 0 deletions

View file

@ -6395,6 +6395,7 @@ ZEND_METHOD(ReflectionReference, getId)
ZEND_METHOD(ReflectionAttribute, __construct)
{
_DO_THROW("Cannot directly instantiate ReflectionAttribute");
}
ZEND_METHOD(ReflectionAttribute, __clone)

View file

@ -0,0 +1,25 @@
--TEST--
ReflectionAttribute cannot be instantiated directly
--FILE--
<?php
#[Attribute]
class A {}
class Foo {
#[A]
public function bar() {}
}
$rm = new ReflectionMethod(Foo::class, "bar");
$attribute = $rm->getAttributes()[0];
$rm = new ReflectionMethod($attribute, "__construct");
try {
var_dump($rm->invoke($attribute, 0, 1, 2));
} catch (ReflectionException $exception) {
echo $exception->getMessage();
}
?>
--EXPECT--
Cannot directly instantiate ReflectionAttribute