php-src/ext/reflection/tests/ReflectionAttribute_constructor_001.phpt
Máté Kocsis fc04a6ebdd
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.
2022-05-03 21:23:22 +02:00

26 lines
492 B
PHP

--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