rspec/rules/S4833/php/rule.adoc

42 lines
1.2 KiB
Plaintext

PHP 5.3 introduces http://www.php.net/namespaces[namespaces] to the language. Use of this mechanism should be preferred to ``++include++`` or ``++include_once++`` or ``++require++`` or ``++require_once++`` because it solves two common problems:
* it avoids name collisions
* it provides the ability to create alias which improve readability of the code
Starting from its version 8, Drupal is relying on namespaces to be compliant with https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md[PSR-4 standard]. Drupal's modules should be compliant with PSR-4 standard and therefore should no longer rely on ``++include++`` or ``++include_once++`` or ``++require++`` or ``++require_once++`` functions.
== Noncompliant Code Example
----
require_once('./modules/vegetable/src/Entity/Tomato.php');
----
== Compliant Solution
----
use Drupal\vegetable\Entity\Tomato
----
== Exceptions
This rule doesn't raise issues on ``++autoload.php++`` or ``++ScriptHandler.php++`` files.
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]