1
votes

I am getting following error why is this?

Fatal error: Can't use method return value in write context

foreach ($transfer_nids as $nid) {
    $wrapper = entity_metadata_wrapper('node', $nid);
    $Result[] = array(
        'S_name' => empty($wrapper->field_s->value()->title) ? 'no data' : $wrapper->field_s->value()->title,
        'r_name' => empty($wrapper->title->value()) ? 'no data' : $wrapper->title->value(),
        'max' => empty($wrapper->field_max->value()) ?  'no data' : $wrapper->field_max->value(),
        );
  }

return ai_wrap_result($Result, 'Info');
}
2
post your complete function, but for the moment i think its suggests that return ai_wrap_result($Result, 'Info'); is returning null - noobie-php
How are you calling this function, I guess you are checking if the response of this function is empty - Muhammad Bilal
@noobie-php: null? if it returns null will it show the same error?actually i am new to php ! can you tell me what i need to do - kashish

2 Answers

0
votes

In (older versions) of PHP (<5.5) you can't use empty() on the return of a function directly, for compiler reasons.

What you need to do instead is save the result in an intermediary variable and check if that is empty() instead, i.e.,

foreach ($transfer_nids as $nid) {
    $wrapper = entity_metadata_wrapper('node', $nid);

    $rName = $wrapper->title->value();
    $max = $wrapper->field_max->value();
    $Result[] = array(
        'S_name' => empty($wrapper->field_s->value()->title) ? 'no data' : $wrapper->field_s->value()->title,
        'r_name' => empty($rName) ? 'no data' : $wrapper->title->value(),
        'max' => empty($max) ?  'no data' : $wrapper->field_max->value(),
    );
}
return ai_wrap_result($Result, 'Info');
0
votes

In older versions of PHP (at least 5.3, but not 5.6), you cannot access members of objects returned by a method:

$wrapper->field_s->value()->title

You must either upgrade your version of PHP, or use a temporary variable.