Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Php: Parentheses when creating new object? [duplicate]

Tags:

php

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?

like image 702
Explosion Pills Avatar asked Jul 26 '11 13:07

Explosion Pills


2 Answers

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

like image 109
Dor Avatar answered Sep 23 '22 11:09

Dor


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.

like image 42
Jimmie Lin Avatar answered Sep 23 '22 11:09

Jimmie Lin