-4

When there are no arguments, we have these two options:

$obj = new MyClass;

vs.

$obj = new MyClass();

I always pick the former, just because.

Any thoughts?

  • 3
    Duplicate from stackoverflow: stackoverflow.com/questions/6830401/… – Asaf Aug 31 '12 at 21:27
  • And also: stackoverflow.com/questions/3873111/… – Jack Sep 1 '12 at 1:43
  • 4
    You can't duplicate questions cross-network. Specific, answerable questions about coding standards/conventions are on-topic here. – user8 Sep 5 '12 at 12:45
  • However, given the existence of the question on Stack Overflow you have to wonder why felt the need to ask it here. – ChrisF Sep 5 '12 at 12:56
  • 1
    @ChrisF Oh I'm sorry. Next time I'll just read the entire internet to avoid bothering you with my "duplicate". – ChocoDeveloper Sep 6 '12 at 9:22
7

Include them. It isn't much extra work and it won't confuse people that don't know that leaving them off the parenthesis is an option.

  • 1
    +1 I didn't know you could leave them off. It would have confused me! – punkrockbuddyholly Sep 5 '12 at 13:03
3

Include them; with PHP, you want to be as specific and unambiguous as you can.

  • 6
    In ANY programming, you want to be as specific and unambiguous as you can. – Jeremy J Starcher Sep 1 '12 at 0:25
  • 1
    @JeremyJStarcher Though this isn't really ambiguous, just confusing for people who don't know about this optional syntax. – ChocoDeveloper Sep 1 '12 at 4:17
  • Yes, it's not really possible for one to be ambiguous in a programming language, as far as the computer is concerned, because it still knows what to do. Rather I meant that dropping little bits of unnecessary syntax here and there is a slippery slop of special cases that results in code that simply takes longer for other humans, or your future self, to understand. – Eliot Ball Sep 1 '12 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.