46

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

Isti115
  • 2,418
  • 3
  • 29
  • 35
kta
  • 19,412
  • 7
  • 65
  • 47
  • 8
    StudlyCaps ( MyClass, ClientServiceClass, MyInterface... ) camelCase (myVar, i, iCount, ...) – Eric Oct 16 '19 at 14:09

5 Answers5

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.

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
  • 3
    It's worth noting that outside of PSR, studly caps refers to ArbItrAry cApItAlIzAtIOn. https://en.wikipedia.org/wiki/Studly_caps – broofa Aug 17 '19 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. – Florian Doyen Feb 25 '20 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.

dave
  • 11,641
  • 5
  • 47
  • 65
10

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.

cofirazak
  • 562
  • 6
  • 16
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..

Hasan Othman
  • 68
  • 1
  • 10
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

Hossein
  • 21
  • 4