1
0
mirror of https://github.com/php/php-src.git synced 2026-04-21 23:18:13 +02:00
Files
archived-php-src/ext/reflection/tests/gh8982.phpt
T
Ilija Tovilo 565a416e87 Fix attribute target validation on fake closures
Fixes GH-8982
Closes GH-9173
2022-07-29 12:14:44 +02:00

53 lines
834 B
PHP

--TEST--
GH-8982 (Attribute target validation fails when read via ReflectionFunction)
--FILE--
<?php
#[Attribute(Attribute::TARGET_FUNCTION)]
class F
{
}
#[Attribute(Attribute::TARGET_METHOD)]
class M
{
}
class C
{
#[F]
#[M]
public function m()
{
}
}
#[F]
#[M]
function f() {}
function test(string $attributeClass, $value) {
try {
var_dump((new ReflectionFunction($value))->getAttributes($attributeClass)[0]->newInstance());
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
}
$m = [new C(), 'm'](...);
$f = f(...);
test(F::class, $f);
test(M::class, $f);
test(F::class, $m);
test(M::class, $m);
?>
--EXPECT--
object(F)#4 (0) {
}
Attribute "M" cannot target function (allowed targets: method)
Attribute "F" cannot target method (allowed targets: function)
object(M)#4 (0) {
}