Member-only story

Learning about PHP Coding Style

Jangwook Kim
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.

  1. PHP code MUST use only<?php &<?= tags.
  2. PHP code MUST use only UTF-8 without BOM.
  3. A file SHOULD either declare new symbols (classes, functions, constants, etc.) or cause side effects, but SHOULD NOT do both.
  4. Namespaces and classes MUST follow PSR-0: Autoloading Standard & PSR-4: Autoloader.
  5. Classes MUST be declared in Pascal Case(PascalCase) or
  6. Constants of classes MUST be declared in All Caps Snake Case(ALL_CAPS_SNAKE_CASE).
  7. Methods MUST be declared in Camel Case(camelCase).

PSR-12: Extended Coding Style

--

--

Jangwook Kim
Jangwook Kim

Written by Jangwook Kim

Korean, live in Japan. The programmer. I love to learn something new things. I’m publishing my toy projects using GitHub. Visit https://www.jangwook.net.

No responses yet