Views: 3216
Last Modified: 29.03.2022

Interface for accessing object as an array can ensure backward compatibility when switching from arrays to objects:

$author = \Bitrix\Main\Test\Typography\AuthorTable::getByPrimary(17)->fetchObject();
		
echo $author['NAME'];
// call is similar to the method $author->getName()

$author['NAME'] = 'New name';
// call is similar to the method $author->setName('New name')

As to runtime fields, you may only read their values in this case, but not set them:

$author = \Bitrix\Main\Test\Typography\AuthorTable::query()
	->registerRuntimeField(
		new \Bitrix\Main\Entity\ExpressionField('FULL_NAME', 'CONCAT(%s, " ", %s)', ['NAME', 'LAST_NAME'])
	)
	->addSelect('ID')
	->addSelect('FULL_NAME')
	->where('ID', 17)
	->fetchObject();

echo $author['FULL_NAME'];
// call is similar to the method $author->get('FULL_NAME');

$author['FULL_NAME'] = 'New name';
// throws exception




Courses developed by Bitrix24