![New in PHP 8.4: new MyClass()->method() Without Parentheses cover image](/assets/img/2025/PHP84-new-myclass-method-without-parentheses.png)
New in PHP 8.4: new MyClass()->method() Without Parentheses
Scott Keck-Warren • January 25, 2025
The 8.4 release of PHP added logic so if we're creating a class and then immediately calling a helper function inside the class the class initialization no longer needs to be in parenthsis.
<?php
class User
{
public function doSomething(): void
{
echo "This is something", PHP_EOL;
}
}
// pre-8.4
(new User())->doSomething();
// post-8.4
new User()->doSomething();
Want to Know More?
I did a whole article for php[achitect] on fun new features in PHP 8.4 where I got into more details. It's also available in a video version if you're so inclined.