7

Possible Duplicate:
Instantiate a class with or without parentheses?

This is a minor quibble, but is there any reason to prefer

$obj = new SomeClass();

over

$obj = new SomeClass;

I prefer the latter because I like how it looks, and it saves you a couple of characters. On the downside, it goes against conventions and makes it slightly harder to come back and add an argument later.

Anyone have a compelling argument for either, or is this pure semantics?

Community
  • 1
  • 1
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405

2 Answers2

8

Doesn't matter as long as your code is consistent, conventional & clear.

Dor
  • 7,344
  • 4
  • 32
  • 45
2

The parentheses are for passing arguments into __construct. Just keep one style, and follow it, unless you have to pass arguments into classes.

Of course, you could just go for the new class; format until you need new classtwo($one, $two). That might be a little inconsistent at first, but it'll make sense in the long run.

Though, pure semantics. Just that.

Jimmie Lin
  • 2,205
  • 2
  • 23
  • 35