Views: 15417
Last Modified: 27.05.2021
Name spaces
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.
Full address line can be abridged. Instead \Bitrix\Main\Class::Function()
you can specify Main\Class::Function()
.
Synonyms also can be used instead of long name spaces. To do it, use
is inserted. For example, the following long structure is available:
To abridge it, declare a synonym at the start of the file and use an abridged variant of the call afterwards: