The results of the Class Naming RFC decided that class names should be written in PascalCase (“Upper Camel Case”), with the exception of acronyms, which should be included in UPPERCASE. This RFC proposes to revisit the prior decision, instead treating acronyms like regular words, making classnames consistent PascalCase.
As an example ext/json has JsonException
which should've been JSONException
according to the previous RFC’s results. In fact JsonException’s RFC was created just 3 months (!) after the class naming RFC in September 2017.
Another example is ext/curl which has both CurlHandle
and CURLFile
. CURLFile
predates the RFC, but there's also CURLStringFile
which was added in PHP 8.1 and likely followed CURLFile
’s naming for consistency, but violating the RFC and being inconsistent with CurlHandle
.
ext/random’s Random\Engine\PcgOneseq128XslRr64
would've needed to be called Random\Engine\PCGOneseq128XSLRR64
according to the class naming RFC.
The PDO driver specific sub-classes RFC voted (and accepted) for PHP 8.3 and implemented in PHP 8.4 uses Pdo<Driver>, e.g. PdoOdbc instead of PDOODBC.
It is well-established in accessibility circles that ALL CAPS text is harder to read than Mixed Case, as mixed case provides greater vertical variation between letters, making it easier to read, especially for people with various reading disorders.
Most accessibility organizations recommend against ALL CAPS. For example:
That issue is amplified if multiple acronyms follow each other. One example is the PCGOneseq128XSLRR64
mentioned above: It’s not clear that XSL
(XorShiftLow) and RR
(RandomlyRotate) are two different acronyms.
Likewise PDOODBC
is much harder to parse than PdoOdbc
.
Another example might be JavaScript’s XMLHttpRequest
which incidentally mixes both variants. According to the class naming RFC it would need to be called XMLHTTPRequest
, resulting in 8 consecutive uppercase characters.
Although there is no formal standard in userland for handling initialisms, the most widely used convention is to only capitalize the first letter. For example:
Although this RFC has no direct impact on userland code, normalizing conventions between Internals and userland has many benefits. The PER-CS working group, part of the PHP-FIG, has been asked to adopt a standard for initialisms and would likely follow suit with this RFC if passed.
The class naming policy should be updated to the following, with changes highlighted:
Method names follow the studlyCaps (also referred to as bumpy case or camel caps) naming convention, with care taken to minimize the letter count. The initial letter of the name is lowercase, and each letter that starts a new word is capitalized.
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. Abbreviations, acronyms, and initialisms should be treated like regular words, thus they should be written with an uppercase first character, followed by lowercase characters. Usage of acronyms and initialisms is not allowed if they are not widely adopted and recognized as such.
Diverging from this policy is allowed to keep internal consistency within a single extension, if the name follows an established, language-agnostic standard, or for other reasons, if those reasons are properly justified and voted on as part of the RFC process.
Good method names:
connect() getData() buildSomeWidget() performHttpRequest()
Bad method names:
get_Data() buildsomewidget() getI() performHTTPRequest()
Good class names:
Curl CurlResponse HttpStatusCode Url BtreeMap // B-tree Map UserId // User Identifier Char // Character Intl // Internationalization Ssl\Certificate Ssl\Crl // Certificate Revocation List Ssl\CrlUrl
Bad class names:
curl curl_response HTTPStatusCode URL BTreeMap UserID // User Identifier CHAR INTL SSL\Certificate SSL\CRL SSL\CRLURL
The DOM HTML5 parsing and serialization RFC introduced new class names and method names that violate the updated naming policy, should this RFC be accepted. As part of this RFC, the following changes will be made:
DOM
namespace will be renamed to Dom
, affecting everything contained within it.For the Improve callbacks in ext/dom and ext/xsl RFC the following changes will be made:
Existing class and method names in released versions are not affected, thus there are not backwards incompatible changes. This is a policy RFC.
Next PHP 8.x (PHP 8.4).
SAPIs that expose classes should take the RFC results into account.
Extensions should take the RFC results into account.
None.
None.
None.
None.
Everything that is not a class name of an internal class. Everything that is already in PHP.
None.
None, yet. This RFC will result in changes to:
n/a
男人前列腺在什么位置cl108k.com | 松花粉有什么功效hcv8jop5ns4r.cn | 抖是什么意思hcv8jop3ns3r.cn | 脑供血不足会导致什么后果hkuteam.com | bjd娃娃是什么hcv8jop2ns7r.cn |
长情是什么意思hcv7jop4ns8r.cn | 小肚子鼓鼓的什么原因hcv7jop5ns6r.cn | 轶是什么意思hcv7jop9ns3r.cn | 副县级是什么级别hcv8jop4ns2r.cn | 10月24号是什么星座hcv8jop5ns4r.cn |
甲状腺肿大吃什么药xjhesheng.com | guava是什么水果hanqikai.com | 辟加木念什么hcv8jop8ns3r.cn | 咖啡有什么营养imcecn.com | 飞机下降时耳朵疼是什么原因hcv7jop7ns4r.cn |
对比度是什么意思hcv9jop6ns8r.cn | 生理年龄是什么意思imcecn.com | 沦落什么意思hcv8jop1ns2r.cn | 热毒是什么hcv9jop4ns5r.cn | 羊肉和什么菜搭配最好hcv9jop1ns9r.cn |