The description has strange example with double array_pop.
array_pop(array_pop(field_get_items($entity_type, $entity, 'field_a')))
It will generate something like this: Strict warning: Only variables should be passed by reference in eval() (line 3 of ...\modules\computed_field\computed_field.module(399) : eval()'d code).
Here is working example:

$entity_field[0]['value'] =
  field_get_items($entity_type, $entity, 'field_a')[0]['value'] /
  field_get_items($entity_type, $entity, 'field_b')[0]['value'];

Comments

core44’s picture

Thanks for this, caught me out for a while!

bkirkendall’s picture

Thanks! You saved me so much agony!

sardbaba’s picture

break9’s picture

Issue summary:View changes

to avoid php notices this should be written as:

  $field_a = field_get_items($entity_type, $entity, 'field_a');
  $field_b = field_get_items($entity_type, $entity, 'field_b');
  $entity_field[0]['value'] = $field_a[0]['value'] / $field_b[0]['value'];
arruk’s picture

how would this be used to total a single field with multiple values?

kiricou’s picture

thanks !!!

colan’s picture

Version:7.x-1.0-beta1» 7.x-1.x-dev
Category:Bug report» Task
Status:Active» Needs review

Okay, I think I got this fixed on the doc page over at https://www.drupal.org/node/126522. Please review.

colan’s picture

Just committed this to the in-line example as well. Thanks!

  • colan committed 750681d on 7.x-1.x
    Issue #1896130 by break9, colan: Updated in-line example to avoid new...
colan’s picture

Status:Needs review» Fixed

I'll assume this is fixed for now. Speak up if there are any issues.

Status:Fixed» Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.