Calling method right after `new` keyword in PHP

This post is also available in: Tiếng Việt (Vietnamese)

Today, I got this error when working on an OOP project:

After 5 minutes for researching, i notice that we can not call method right after new keyword.

In older version than PHP 5.4, we can not do anything in this situation and need to write code like this:

Fortunately, we can call direct method right after new keyword in newer version than 5.4, by wrapping all the code in ():

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: