Take the State of PHP 2026 Survey →

Class Naming View as Markdown

Accepted
Authors
Richard Fussenegger, php@fleshgrinder.com
Date
2017-06-03
Version
1.0
Source
wiki.php.net/rfc/class-naming

Votes

Should we update the coding standard? closed
Yes
17
No
9
26 voters
aeoris Yes 2017-07-06 10:09
ajf Yes 2017-07-05 16:34
ashnazg Yes 2017-07-03 14:51
bwoebi No 2017-07-01 20:01
colinodell Yes 2017-07-02 15:46
danack No 2017-07-03 22:04
derick No 2017-07-04 17:10
emir Yes 2017-07-11 09:59
galvao Yes 2017-07-03 06:07
guilhermeblanco Yes 2017-07-06 14:17
heiglandreas No 2017-07-05 18:14
hywan Yes 2017-07-05 17:29
jhdxr No 2017-07-05 12:39
kalle No 2017-07-01 21:29
kelunik No 2017-07-08 18:45
kguest Yes 2017-07-18 19:51
laruence Yes 2017-07-06 07:11
mbeccati Yes 2017-07-03 15:34
narf Yes 2017-07-03 11:49
ocramius Yes 2017-07-02 11:54
omars Yes 2017-07-06 09:29
peehaa No 2017-07-01 18:56
remi No 2017-07-07 07:49
sammyk Yes 2017-07-03 15:15
stas Yes 2017-07-01 21:21
zeev Yes 2017-07-03 08:02
What class naming style should we use? closed
PascalCase except Acronyms
15
Always PascalCase
11
26 voters
aeoris Always PascalCase 2017-07-06 10:10
ashnazg Always PascalCase 2017-07-03 14:51
bwoebi PascalCase except Acronyms 2017-07-03 20:51
cmb Always PascalCase 2017-07-04 14:10
colinodell Always PascalCase 2017-07-01 21:17
danack Always PascalCase 2017-07-04 21:11
derick PascalCase except Acronyms 2017-07-04 17:09
emir PascalCase except Acronyms 2017-07-11 09:59
galvao PascalCase except Acronyms 2017-07-03 06:07
guilhermeblanco PascalCase except Acronyms 2017-07-06 14:17
heiglandreas PascalCase except Acronyms 2017-07-05 18:15
hywan Always PascalCase 2017-07-05 17:31
kalle Always PascalCase 2017-07-03 18:37
kelunik PascalCase except Acronyms 2017-07-08 18:37
kguest PascalCase except Acronyms 2017-07-18 19:51
laruence PascalCase except Acronyms 2017-07-06 07:11
mbeccati PascalCase except Acronyms 2017-07-03 15:37
narf PascalCase except Acronyms 2017-07-03 11:54
ocramius PascalCase except Acronyms 2017-07-02 11:54
omars PascalCase except Acronyms 2017-07-06 09:29
pollita PascalCase except Acronyms 2017-07-02 18:43
sammyk Always PascalCase 2017-07-03 15:15
stas PascalCase except Acronyms 2017-07-01 21:21
subjective Always PascalCase 2017-07-07 19:28
yunosh Always PascalCase 2017-07-03 08:58
zeev Always PascalCase 2017-07-03 08:02

Discussions on the mailing list

Class Naming in Core
by Fleshgrinder · 30 messages
[RFC] [Discussion] Class Naming
by Fleshgrinder · 16 messages
[RFC] [Voting] Class Naming
by Fleshgrinder · 8 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:50 UTC

Introduction

The PHP coding standard does not cover how class names should be written. This leads to friction within the userland community that is now largely following the standard recommendation PSR-1. Extending our current coding standard to cover edge cases about abbreviations and acronyms/initialisms would resolve any future discussion.

Proposal

Extend the coding standard to explicitly specify how abbreviations and acronyms/initialisms are to be handled when writing user-level class names. The current rule is:

Classes should be given descriptive names. Avoid using abbreviations where possible. Each word in the class name should start with a capital letter, without underscore delimiters (CamelCaps starting with a capital letter). The class name should be prefixed with the name of the 'parent set' (e.g. the name of the extension)::

Good: 'Curl' 'FooBar'

Bad: 'foobar' 'foo_bar'

— CODING_STANDARD

While it is stated that abbreviations should be avoided, it is silent on what to do if they are used; especially in the case of acronyms/initialisms. There are essentially three choices possible now:

  1. PascalCase except Acronyms/Initialisms — which is how the majority of user-level class names are written, and it matches the approach of many other programming languages.
  2. Always PascalCase — which is basically what PSR-1 defines, however, it would make most of the currently existing user-level class names invalid.
  3. Do Nothing — which of course automatically means that any approach is allowed, and the community discussions around this topic will continue.

IMPORTANT!

Regardless of the outcome of this RFC, existing user-level class names are not required to be changed. Although it would be possible (class names are case-insensitive). The reason why renaming is not proposed is simple: this RFC would most probably fail because too many people are against such purely cosmetic changes.

IMPORTANT!

PascalCase except Acronyms/Initialisms

Class names should be descriptive nouns in PascalCase and as short as possible. Each word in the class name should start with a capital letter, without underscore delimiters. The class name should be prefixed with the name of the “parent set” (e.g. the name of the extension) if no namespaces are used. Abbreviations and acronyms as well as initialisms should be avoided wherever possible, unless they are much more widely used than the long form (e.g. HTTP or URL). Abbreviations start with a capital letter followed by lowercase letters, whereas acronyms and initialisms are written according to their standard notation. Usage of acronyms and initialisms is not allowed if they are not widely adopted and recognized as such.

Good: 'Curl' 'CurlResponse' 'HTTPStatusCode' 'URL' 'BTreeMap' (B-tree Map) 'Id' (Identifier) 'ID' (Identity Document) 'Char' (Character) 'Intl' (Internationalization) 'Radar' (Radio Detecting and Ranging)

Bad: 'curl' 'curl_response' 'HttpStatusCode' 'Url' 'BtreeMap' 'ID' (Identifier) 'CHAR' 'INTL' 'RADAR' (Radio Detecting and Ranging)

— GitHub PR #2552

Always PascalCase

Class names should be descriptive nouns in PascalCase and as short as possible. Each word in the class name should start with a capital letter, without underscore delimiters. The class name should be prefixed with the name of the “parent set” (e.g. the name of the extension) if no namespaces are used. Abbreviations and acronyms as well as initialisms should be avoided wherever possible, unless they are much more widely used than the long form (e.g. HTTP or URL). Abbreviations, acronyms, and initialisms follow the same letter-casing as any other word.

Good: 'Curl' 'CurlResponse' 'HttpStatusCode' 'Url' 'BTreeMap' (B-tree Map) 'Id' (Identifier and Identity Document) 'Char' (Character) 'Intl' (Internationalization) 'Radar' (Radio Detecting and Ranging)

Bad: 'curl' 'curl_response' 'HTTPStatusCode' 'URL' 'BtreeMap' 'ID' 'CHAR' 'INTL' 'RADAR'

— GitHub PR #2553

Backward Incompatible Changes

None, we only update the coding standards for the future.

Future Scope

  • Update existing user-level class names according to the outcome of this RFC.

Proposed Voting Choices

Simple 50%+1 majority vote:

Vote: Should we update the coding standard? — Yes: 17 · No: 9 (closed)

Vote: What class naming style should we use? — PascalCase except Acronyms: 15 · Always PascalCase: 11 (closed)

Patches and Tests

References