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

Call Method On New

It was not possible to call a method directly after instantiating an object: the instantiation had to be done within a parenthesis.

In PHP 8.4, it is now possible to call directly a method after instantiation, as long as the new call includes the parenthesises.

PHP code

<?php

class x {} 

new x()->a();

// This is not possible: it's missing the parenthesis
//new x->a();

?>

Before

PHP Parse error:  syntax error, unexpected token "->" 

Parse error: syntax error, unexpected token "->" 

After


PHP version change

This behavior changed in 8.4.

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat