Skip to content

Latest commit

 

History

History
37 lines (29 loc) · 1.58 KB

code-standard-php.md

File metadata and controls

37 lines (29 loc) · 1.58 KB
group subgroup title landing-page menu_title menu_order redirect_from functional_areas
coding-standards
01_Coding standards
PHP coding standard
Coding standards
PHP coding standard
2
/guides/v1.0/coding-standards/code-standard-php.html
Standards

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

Where possible, use PHP_CodeSniffer{:target="_blank"} 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{:target="_blank"} {% glossarytooltip caa46cea-25d7-4e4f-bce1-11430ada59dc %}keyword{% endglossarytooltip %} 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
  • {% glossarytooltip 621ef86b-7314-4fbc-a80d-ab7fa45a27cb %}Namespace{% endglossarytooltip %} relative class name
  • Import relative class name

Examples:

{% highlight php startinline=true %} $this->get(ClassName::class); {% endhighlight %}

{% highlight php startinline=true %} $this->get(\Magento\Path\To\Class::class); {% endhighlight %}