Nested Attributes

Attributes can handle nested new calls since PHP 8.1. They can use literals, constants and now, full objects as part of the attribute expression.

PHP code

<?php

#[JoinTable(joinColumns: [new JoinColumn])]
class x {
     function __construct() {
             print __METHOD__;
     }
}

new x;

?>

Before

PHP Fatal error:  Constant expression contains invalid operations in /codes/nestedAttributes.php on line 4

Fatal error: Constant expression contains invalid operations in /codes/nestedAttributes.php on line 4

After

x::__construct

PHP version change

This behavior changed in 8.1