tags:

views:

41

answers:

2

Usually I create a new object invocating his constructor the 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.

+4  A: 

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;
cletus
Just what I was searching. Thanks
Eineki
A: 

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

pagboy
Unfortunately, PHP doesn't support multiple constructors. Nice try though. :)
fireeyedboy
Re: No multiple constructors. True, however you can omit them and if default values are provided in the signature they will be substituted in when the call is made.
sfrench