Instantiate a class with or without parentheses?

Php

Php Problem Overview


> Possible Duplicate:
> PHP class instantiation. To use or not to use the parentheses?

I have not found any official documentation on this. But afaik it doesn't matter whether a class is instantiated with our without the parentheses - as long as there are no parameters involved, right?

$car = new Car;

or

$car = new Car();

But can anyone tell me if there's a difference in performance? Which way is the 'more correct' way? Is there any official documentation for this?

Php Solutions


Solution 1 - Php

Any difference in performance is going to be absolutely negligible.

While both ways are fine, I personally would prefer using new Car(); because usually, a method is being called here, and function/method calls in PHP require (). Also, it's more consistent with instantiations that have parameters.

But in the end, it's down to taste. It doesn't matter which way you choose, but when you choose one, stick to it consistently!

Solution 2 - Php

the first instantiation has no "official" reference. In the official php doc you alway find the second one. So, i'de prefere this for consistenscy. But it's all your choice

Solution 3 - Php

They're both correct ways, and I'm sure there isn't any difference in performance either.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFrankView Question on Stackoverflow
Solution 1 - PhpPekkaView Answer on Stackoverflow
Solution 2 - PhpArtoAleView Answer on Stackoverflow
Solution 3 - Phpreko_tView Answer on Stackoverflow