0

I'm trying to take into consideration the PSR-0 and PSR-1 recommendations made by my IDE (Netbeans here). PSR-1 says both:

Class names MUST be declared in StudlyCaps.

and :

Method names MUST be declared in camelCase.

That's of course very fine, but how are we supposed to comply in the case of constructors named like the class? Is it somehow implied that the first rule must take precedence in this case (and in that kind of document, I really really don't think anything should be implied)? I can't seem to make the warnings disappear without disabling the PSR-1 recommendations. Is Netbean's checker just a bit too psychorigid?

Eusebius
  • 531
  • 6
  • 24
  • I have those line warnings enabled and NetBeans doesn't complain about my constructors or other "magic methods" – rink.attendant.6 May 05 '15 at 13:20
  • 3
    Can't see the conflict myself.... the constructor for a classname is always a method called `__construct`.... ___don't___ use the classname as a constructor method name as this is only permitted for backward compatibility with PHP4, and is now officially deprecated - http://www.php.net/manual/en/language.oop5.decon.php – Mark Baker May 05 '15 at 13:23
  • @MarkBaker: OK thanks, that was my mistake, I kept using constructors named like in Java or C++, it worked so I never realized that this was deprecated. I have edited my question to make it clearer. Would you care to rephrase as an answer to my question, so that I can accept it? – Eusebius May 05 '15 at 13:56

1 Answers1

3

Don't use constructors named like the class, use __contruct() instead.

As noted in PHP constructors documentation, PHP seems to search for class-named-constructors only for backwards compatibility.

samuel
  • 326
  • 2
  • 9