21

I get the following error:

Strict warning: Only variables should be passed by reference in include() (line 18 of /home/sites/dev/theparce/sites/all/themes/parce/block--block--3.tpl.php).

This is the block code which is causing that error.

if ($user_gallery) {
  print render(node_show($user_gallery));  // Line 18
  print drupal_render ($user_gallery_edit);

}
else {
  print drupal_render($user_gallery_new);
}

Why do I get that error, even if I get all printed as expected?

52

That error happens when a function is expecting a reference as parameter, but it is not getting a reference.

In your case, render() is defined as render(&$element), but node_show() is defined as node_show($node, $message = FALSE), not &node_show($node, $message = FALSE).
The same would be true for drupal_render(), since the function is defined as drupal_render(&$elements).

As explained on Passing by Reference, when a function requires a reference parameter, you can pass to the function:

  • Variables (for example, a temporary variable containing the result of a function which is not returning a reference)

  • References returned from functions

Using other expressions, the result is undefined, and it depends from the PHP version.

  • render(node_show()) produces a fatal error in PHP 5.0.5, a strict standards notice in PHP 5.1.1, and a notice in PHP 7.0.0

  • render(5) produces a fatal error

  • render(new DateTime()) produces a notice in PHP 7.0.7

protected by Community Apr 3 '16 at 5:56

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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