1--TEST--
2Closure in attribute may not access unrelated 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 (E $e) {
14    echo $e->secret, PHP_EOL;
15})]
16class C {
17}
18
19class E {
20    public function __construct(
21        private string $secret,
22    ) {}
23}
24
25foreach ((new ReflectionClass(C::class))->getAttributes() as $reflectionAttribute) {
26    ($reflectionAttribute->newInstance()->value)(new E('secret'));
27}
28
29?>
30--EXPECTF--
31Fatal error: Uncaught Error: Cannot access private property E::$secret in %s:%d
32Stack trace:
33#0 %s(%d): C::{closure:%s:%d}(Object(E))
34#1 {main}
35  thrown in %s on line %d
36