PHP PSR-1: Basic Coding Standard

What is PSR

And why it's that important to know?

Who uses PSR?

PSR stands for PHP Standards Recommendations.

PHP Framework Interop Group! We're a group of established PHP projects whose goal is to talk about commonalities between our projects and find ways we can work better together.

PSR are groups of rules to standardize the way of coding in PHP in general.

But this post will be talking about PSR-1 only.

So here is a quick rules to take care of while you're coding:

  • Files MUST use only <?php and <?= tags.

  • Files MUST use only UTF-8 without BOM for PHP code.

  • Files SHOULD either declare symbols (classes, functions, constants, etc.) or generate output like html content.

  • Namespaces and classes MUST follow an autoloading PSR: [PSR-0, PSR-4].

  • Class names MUST be declared in StudlyCaps.

  • Class constants MUST be declared in UPPER_CASE_WITH_UNDERSCORE.

  • Method names MUST be declared in camelCase.

Why it is important?

Because basically most people will recognize the code you write easily and also you'll when you read theirs.

Who uses PSR?

Most of popular frameworks are using PSR standards like:

  • Symfony -Doctrine
  • Laravel
  • CakePHP
  • Phalcon
  • Drupal
  • Joomla
  • Magento
  • Phalcon
  • Composer
  • PEAR
  • ReactPHP
  • PrestaShop
  • Slim
  • Yii framework
  • Zend Framework

And many more.


Comments (2)

Mohamed Aboelmaged
Mohamed Aboelmaged
8 months ago

StickyCaps, StudlyCaps or UpperCamelCase.

Hasan Zohdy
Hasan Zohdy
8 months ago

There is another name for StudlyCase, do you know what is it?