Kamran Ahmed
Kamran Ahmed

Reputation: 12428

Difference between object creation using `new ClassName` and `new ClassName()` in PHP

I know, in PHP, we can create an object using new ClassName and also using new ClassName() (notice the parenthesis). Is there ANY difference between both of these ways at all?

Upvotes: 4

Views: 144

Answers (2)

deceze
deceze

Reputation: 522005

Nope, no difference whatsoever. If you don't need to pass parameters to the constructor, the parentheses are entirely superfluous.

Upvotes: 7

xdazz
xdazz

Reputation: 160833

No, there is no difference.

The () is required only if you have to pass parameters to the constructor, otherwise it could be omitted.

Upvotes: 3

Related Questions