I am getting this error on this line in my code. I'm guessing I need to break this line down a bit. Any comments would be great.

$promobox_id = reset(array_keys($result['fieldable_panels_pane']));
  • reset() is supposed to be called with an array variable which is passed by reference. you are sending it the results of array_keys() instead. if you do $x=array_keys(....) and then $promobox_id=reset($x) the error should go away. – Jimajamma Apr 30 '13 at 16:09
  • I am going to close this question since the code involved in the error is not using any Drupal function, but only PHP functions. If the code used at least one Drupal function, answering the question would require at least to know if the function returns a reference. – kiamlaluno Apr 30 '13 at 16:53

That's not a Drupal error. It's a PHP error. You're getting it because the reset function expects an array to be passed by reference. You are passing it the return value of the array_keys function, which does not return its result by reference.

If you want to break down your code to avoid this error, try something like this:

$array_keys = array_keys($result['fieldable_panels_pane']);
$promobox_id = reset($array_keys);

Also, consider seeing this page for more information: http://www.php.net/manual/en/language.references.pass.php

| improve this answer | |

Change it to:

$arr = array_keys($result['fieldable_panels_pane']);
$promobox_id = reset($arr);

reset() takes the first parameter by reference, which should be a variable as the exception suggests. (not the direct result of a function execution).

You'll probably see a lot of these if you've recently upgraded to PHP5.4.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.