PHP coding standard

The Magento core development team uses the PSR-1: Basic Coding Standard and PSR-2: Coding Style Guide. Magento recommends that developers who create Magento extensions and customizations also use these standards.

Where possible, use PHP_CodeSniffer to automatically enforce these standards. Otherwise, you must apply these standards and requirements through rigorous code review.

Class name resolution standard

For class name resolution, use the ::class keyword instead of a string literal for every class name reference outside of that class. This includes references to:

  • Fully qualified class name
  • Imported/non-imported class name
  • Namespace relative class name
  • Import relative class name

Examples:

  $this->get(ClassName::class);
  $this->get(\Magento\Path\To\Class::class);