Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

Fatal error: Constant expression contains invalid operations

After

x::__construct

PHP version change

This behavior changed in 8.1.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat