1--TEST-- 2Closure in attribute may access private variables 3--EXTENSIONS-- 4reflection 5--FILE-- 6<?php 7 8#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] 9class Attr { 10 public function __construct(public Closure $value) {} 11} 12 13#[Attr(static function (C $c) { 14 echo $c->secret, PHP_EOL; 15})] 16class C { 17 public function __construct( 18 private string $secret, 19 ) {} 20} 21 22foreach ((new ReflectionClass(C::class))->getAttributes() as $reflectionAttribute) { 23 ($reflectionAttribute->newInstance()->value)(new C('secret')); 24} 25 26?> 27--EXPECT-- 28secret 29