Views: 1399 (Data available since 06.02.2017)

The notion of name spaces permits giving system elements clearer names, getting rid of numerous name prefixes, and also avoiding potential conflicts. All classes delivered in a standard installation package must be located in the Bitrix name space that does not overlap either with PHP or with partner implementations. Each standard module determines its subspace in the Bitrix name space which coincides with the module name. For example, for the forum module Bitrix\Forum will be the name space, and for the main module – Bitrix\Main.

Note. For partner classes, the namespace can be as follows:
namespace Asd\Metrika;  
 
class CountersTable extends Entity\DataManager  
{  
   ....

This means that this class (in /lib/) belongs to the module asd.metrika and it can be addressed as follows (after the indicated module is connected):

\Asd\Metrika\CountersTable::update();

The class itself is located in the file asd.metrika/lib/counters.php.

If necessary, a module may organize subspaces inside its name space. For example, Bitrix\Main\IO, Bitrix\Forum\Somename\Somename2. But this option should be used only if it is justified for the organization of a correct architecture of this module.


Naming Rules

  • Name spaces must be named in “UpperCamelCase.”
  • Names cannot contain any symbols but for Latin letters.
  • Class name must be a noun. Unnecessary acronyms and abbreviations should be avoided.

Examples:

namespace Bitrix\Main\Localization;
namespace Bitrix\Main\Entity\Validator;

Abbreviations that are not generally accepted (in Bitrix Framework) cannot be used.



Courses developed by «Bitrix», Inc.