mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
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:
parent
ef5478b823
commit
fc04a6ebdd
2 changed files with 26 additions and 0 deletions
|
@ -6395,6 +6395,7 @@ ZEND_METHOD(ReflectionReference, getId)
|
||||||
|
|
||||||
ZEND_METHOD(ReflectionAttribute, __construct)
|
ZEND_METHOD(ReflectionAttribute, __construct)
|
||||||
{
|
{
|
||||||
|
_DO_THROW("Cannot directly instantiate ReflectionAttribute");
|
||||||
}
|
}
|
||||||
|
|
||||||
ZEND_METHOD(ReflectionAttribute, __clone)
|
ZEND_METHOD(ReflectionAttribute, __clone)
|
||||||
|
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue