Reputation: 769
It's quite common in PHP world to capitalize class names (usually using UpperCamelCase vs lowerCamelCase for objects, but also methods and sometimes functions). I understand that this is a common practice in many programming languages to avoid naming conflicts, like classes vs objects. On the second thought however, it probably makes sense in C++ or Java, but in PHP the dollar sign makes it rather clear what is a class and what is an instance of a class. So, are there some reasons other than "widespread practice" or (a bit arbitrary) readability that rationalize using separate naming convention for classes? What are the potential naming conflicts?
In fact the other case where capitalized names are used commonly in PHP are namespaces. And that makes me state a similiar question: what is the rationale behind separate naming convention for namespaces in PHP? Are there some potential naming conflicts? Or is it just a convention borrowed from other languages?
Upvotes: 4
Views: 258
Reputation: 2328
As far as I know this initially evolved purely as a stylistic choice among framework developers several years ago. As PHP has evolved from a framework-centric ecosystem to more of a package-centric ecosystem (thanks in large part to Composer) many of the major framework developers came together to create the Framework Interoperability Group. The intent of the group was "to talk about the commonalities between our projects and find ways we can work together."
Several standards documents have been drafted and voted over the past couple of years, including PSR-1 which defines a basic coding standard that includes the directive to declare classes in "StudlyCaps". This standard has been adopted by a large majority of frameworks and libraries since its introduction which is why you now see it almost everywhere.
Upvotes: 1