This works fine:
$entity->field_time[LANGUAGE_NONE][0] = array(
'value' => date_format($date),
'timezone' => 'UTC',
);
But I need to make it more generic, to allow for different field names. So I try to use a constant:
define('FIELD_TIME', 'field_time');
$entity->FIELD_TIME[LANGUAGE_NONE][0] = array(
'value' => date_format($date),
'timezone' => 'UTC',
);
But this does not target the correct array name, which should be [field_time][LANGUAGE_NONE][0]
I also tried:
define('FIELD_TIME', 'field_time');
$entity->constant('FIELD_TIME')[LANGUAGE_NONE][0] = array(
'value' => date_format($date),
'timezone' => 'UTC',
);
But that throws: Parse error: syntax error, unexpected '['
What am I doing wrong?
public $_arr = array(...);and in another filedefine('BLA', '_arr');. OP wants to do$obj->_arr = ...but using constant value =>$obj->BLA =FIELD_TIMEis a constant of the class, shouldn't it be accessed statically likeEntityClass::FIELD_TIME?class Entity { public $field_time = null; } $entity = new Entity(); define('FIELD_TIME', 'field_time');ArrayCollectionor even old fashioned magic be more suitable?