开发者

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

开发者 https://www.devze.com 2023-03-06 20:18 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: PHP class instantiation. To use or not to use the parenthesis?
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

精彩评论

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