Question

Strict warning: Only variables should be passed by reference in include() (line 26 of page.tpl.php).

Posted January 20, 2014 10k views
Hello Support Team, I have got this error after upgrade my php version from 5.3.10 to 5.5.7. My application is running in drupal 7.23 in ubuntu 12.04. Error : Strict warning: Only variables should be passed by reference in include() (line 26 of /var/www/avcdistributor.com/sites/all/themes/tejas/templates/page.tpl.php). Line 24-28 Says : if($user->uid != 0){ $block = block_load('block', '7'); $output = drupal_render(_block_get_renderable_array(_block_render_blocks(array($block)))); print $output; } Can you please help me what is the issue, it will perfectly worked on php 5.3.10, but after upgrade php version it will not working. Thanks, Tejas

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
3 answers
For more information on resolving this issue with your code, please refer to: http://www.php.net/manual/en/language.references.pass.php

[Not recommended]
However, to prevent this warnings from displaying, add "~E_STRICT" to your php.ini on the error_reporting line. Such as:
error_reporting = E_ALL ~E_STRICT
> it was perfectly worked on php 5.3.10, but after upgrade php version it will not working.

The reason you are seeing this message after upgrading, is that strict warnings (E_STRICT) became part of E_ALL in 5.4.0. The default value for `error_reporting` in 5.5.7 excludes E_STRICT, however if you didn't alter your php.ini file, you will still have the 5.3 default which doesn't exclude E_STRICT:

5.3: # Default Value: E_ALL & ~E_NOTICE

5.5: # Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED

The correct action to resolve this is to add `& ~E_STRICT` to your existing error_reporting value in php.ini.

http://php.net/manual/en/function.error-reporting.php#refsect1-function.error-reporting-changelog
the problem you are having is that you are passing the return of the function call "_block_get_renderable_array" to drupal_render. drupal_render expects that parameter to be passed by reference. You can only pass a variable by reference NOT the return value of a function call. Here is an example fix.
$block = block_load('block', '7');
$render_block = _block_get_renderable_array(_block_render_blocks(array($block)))
$output = drupal_render($render_block);
print $output;
Submit an Answer