Member-only story
Learning about PHP Coding Style
3 min readJan 26, 2020
I know that common coding style is helpful for cooperation. But unfortunately, I’m working alone so I didn’t understand it’s importance.
When I decide refactoring my legacy source code, I found the QUITE DIRTY CODE. So I make up my mind studying about PHP coding style.
PSR-1: Basic Coding Standard
PHP Basic coding standard are described in RFC 2119.
- PHP code MUST use only
<?php
&<?=
tags. - PHP code MUST use only UTF-8 without BOM.
- A file SHOULD either declare new symbols (classes, functions, constants, etc.) or cause side effects, but SHOULD NOT do both.
- Namespaces and classes MUST follow PSR-0: Autoloading Standard & PSR-4: Autoloader.
- Classes MUST be declared in
Pascal Case(PascalCase)
or - Constants of classes MUST be declared in
All Caps Snake Case(ALL_CAPS_SNAKE_CASE)
. - Methods MUST be declared in
Camel Case(camelCase)
.