function FetchModeTrait::assocToClass
Same name in other branches
- 11.x core/lib/Drupal/Core/Database/FetchModeTrait.php \Drupal\Core\Database\FetchModeTrait::assocToClass()
Converts a row of data in FETCH_ASSOC format to FETCH_CLASS.
Parameters
array $rowAssoc: A row of data in FETCH_ASSOC format.
string $className: Name of the created class.
array $constructorArguments: Elements of this array are passed to the constructor.
Return value
object The row in FETCH_CLASS format.
1 call to FetchModeTrait::assocToClass()
- FetchModeTrait::assocToClassType in core/
lib/ Drupal/ Core/ Database/ FetchModeTrait.php - Converts a row of data to FETCH_CLASS | FETCH_CLASSTYPE.
File
-
core/
lib/ Drupal/ Core/ Database/ FetchModeTrait.php, line 105
Class
- FetchModeTrait
- Provide helper methods for statement fetching.
Namespace
Drupal\Core\DatabaseCode
protected function assocToClass(array $rowAssoc, string $className, array $constructorArguments) : object {
$classObj = new $className(...$constructorArguments);
foreach ($rowAssoc as $column => $value) {
$classObj->{$column} = $value;
}
return $classObj;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.