I have classes, each with a date related member variable that always has the same naming format - field_{$node->type}_date
For example, if I my node type was 'car', the date field would be named field_car_date
So I am looping over all my nodes and I want to access the date related field for each of them. However I am getting an error. Here's the code
$date_field_key = 'field_' . $node->type . '_date';
if (isset($node->$date_field_key['und'][0]['value'])) {
I get an error because of the second line. The error is - Illegal string offset 'und'
The date related variable is an array and it does have an element with the key 'und'. If I write out the line explicitly - $node->field_car_date['und'][0]['value'] - it works fine. It's just when I dynamically create the field name that I get this problem.
Any solution for this, is my syntax incorrect?