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?
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!
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With