47

PSR suggests, method names MUST be declared in camelCase and class names MUST be declared in StudlyCaps.

1
  • 8
    StudlyCaps ( MyClass, ClientServiceClass, MyInterface... ) camelCase (myVar, i, iCount, ...)
    – Eric
    Oct 16, 2019 at 14:09

5 Answers 5

68

StudlyCaps, also known as PascalCase, implies that the first capital of each subword is capitalized. camelCase implies, like a camel, that the humps are in the middle, therefore the first letter is not capitalized.

Compare Microsoft's standards for .NET.

Other well known capitalization styles are snake_case, where all words are concatenated in lowercase with underscores, and kebab-case, which is identical but uses a hyphen.

2
  • 3
    It's worth noting that outside of PSR, studly caps refers to ArbItrAry cApItAlIzAtIOn. en.wikipedia.org/wiki/Studly_caps
    – broofa
    Aug 17, 2019 at 13:35
  • 1
    In fact, StudlyCaps seems to be same as CamelCase. The CamelCase you explained is the "lowerCamelCase", which put the first letter in lowercase. Feb 25, 2020 at 14:22
25

CamelCase is where the first letter of each sub-word in a name is capitalised. The first letter of the whole name can be upper or lower case, and is generally (always?) lower case in programming.

StudlyCaps is a little weird. There are capital letters, but they can be at any letter according to some rule, not just the beginning of a sub-word. The classic example is (was) HoTMaiL.

My understanding of the PSRs is that their intention is that each sub-word should be capitalised in both instances, with classes having an initial upper-case letter and methods an initial lower-case letter.

11

In PSR-12 there is an explanation of what they meant by StudlyCaps:

The term ‘StudlyCaps’ in PSR-1 MUST be interpreted as PascalCase where the first letter of each word is capitalized including the very first letter.

source: https://www.php-fig.org/psr/psr-12/#21-basic-coding-standard

TL;DR

For clarity, there are two versions of camel case:

  • UpperCamelCase (initial uppercase letter, also known as PascalCase)
  • lowerCamelCase (initial lowercase letter, also known as dromedaryCase).

Some people and organizations, notably Microsoft (and seems the authors of PSR-1 too), use the term camel case only for lowerCamelCase.

PascalCase (or StudlyCaps) means exactly UpperCamelCase.

2

i call it actually PascalCase when the identifier has two words each one begins with capital letters.. and i use it in C# for methods names, and camelCase for variablesNames, instanceFelds.. ClassNames also for PasaclCase..

0

camelCase:

$camelCase $myVar

Only first letter of sub-words, not first letter of the property itself should be uppercase

StudlyCaps:

$StudlyCaps $MyVar

property starts with uppercase also first letter of sub-words

maybe find it useful: psr property naming recommendation

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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