Views: 11798
Last Modified: 10.10.2024

$arParams

$arParams is a variable redefined for a component which consists of the input parameters of a component. In this array, the names of parameters are the keys, and parameter values are the array values.

Before connecting a component to all parameter values, the function htmlspecialcharsEx is applied. The source values of the parameters are stored in the same array with the same keys but with the prefix ~. For example, $arParams["NAME"] is an input parameter to which the function htmlspecialcharsEx, and $arParams["~NAME"] is a source input parameter.

The variable $arParams is a reference for a component class member. That is why all the changes in this variable are also reflected on such a class member. In the beginning of the component code input parameters must be checked, non-set parameters must be initialized, and adjustment to a required type must be performed (e.g., IntVal()). All these changes in the input parameters will also be available in the template. I.e. parameters in the template will be already checked and as safe as possible. Duplicating parameter preparation in the component template is not required.


$arResult

$arResult is a preset variable for a component to which the component work result is collected for subsequent submission to the template. Before connecting a component file, this variable is initialized by the empty array array().

The $arResult variable is a reference for a component class member. That is why all changes in this variable are also reflected on such a class member. It means that there is no need to submit this variable to the template, since internal mechanisms of the component class will do it.


References in PHP

References in PHP are necessary so that the same data could be accessed using different names. If the variables $arParams and $arResult are somehow changed in the component code, they will be updated and available in the template, too.

At the same time, the following aspects shall be taken into account:

  • If the following code is written in the component:
    $arParams = & $arSomeArray;
    the variable $arParams will be detached from the component class member and attached to the array $arSomeArray.In this case, further changes in $arParams will not get to the component template.
  • If the following, the code is written in the component:
    unset($arParams);
    it will also break the connection between $arParams and the relevant component class member.


Courses developed by Bitrix24