Search code examples
phpprogramming-languagesphp-5.3

Learning PHP but I've noticed the writer of the book I'm using calls objects in 2 different ways


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

I'm learning PHP from an O'reilly book "Learning PHP, MySQL and Javascript". I'm half way through learning about objects etc.

I've noticed that sometimes the writer calls objects in two different ways.

  • $example = new Object
  • $example = new Object()

They both seem to work fine for me. Is there a preferred way or best practice? Is there a reason for this?


Solution

  • Personally I prefer to include the parenthesis. helps to remind you the constructor is a method that you can override.

    But this could just be because I learned OOP in C++.

    Whatever you do, just be consistent.