开发者

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

This question already has answers here: Closed 11 years ago.

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 a开发者_开发知识库bout 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜