开发者

PHP constructor invocation syntax

Usually I create a new object invocating his constructor the开发者_JAVA百科 usual way:

$instance= new Class();

Lately, I'm reading a lot of code with an alternative syntax (without the parentesys):

$instance= new Class;

There are substantial differences between the two methods or are they equivalent?

I haven't found references on this topic 'till now.


There is no difference.

You're right about this being hard to prove. The Basics introduces the new keyword but all examples have parentheses and no mention is made of their optionality.

Edit: best I can find are examples from the official documentation such as:

// This will call B() as a constructor
$b = new B;


I am not familiar with PHP, but the latter probably invokes the default constructor, while the former invokes the constructor with no parameters.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜