-
-
Notifications
You must be signed in to change notification settings - Fork 947
Passing an anonymous class instance to the constructor of another anonymous class errors #11511
Copy link
Copy link
Closed
Labels
Description
Bug report
The following snippet results in an error:
<?php declare(strict_types = 1);
$myObject = new class (new class { public string $bar = 'test'; }) {
public function __construct(public object $foo)
{
}
};
echo $myObject->foo->bar;Property $bar was not found in reflection of class AnonymousClass6bf955dcd48a8ffb510ed90de4f268e1.
Code snippet that reproduces the problem
Expected output
Expected no error
Additional info
Extracting the passed object into a variable first works. (I had to add the object{bar: string} type annotation in this case for the last line not to error, but that doesn't have anything to do with the issue itself.)
<?php declare(strict_types = 1);
$foo = new class { public string $bar = 'test'; };
$myObject = new class ($foo) {
/**
* @param object{bar: string} $foo
*/
public function __construct(public object $foo)
{
}
};
echo $myObject->foo->bar;Reactions are currently unavailable