Generally speaking, when you get the error and the line causing the error is using a function call to pass its return value as parameter of another function, it means that the function getting the parameter is expecting a reference, while the function used to get the value to pass as parameter doesn't return 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)
and it expects a reference as its first argument.
As explained on Passing by Reference, when a function needs a reference as parameter, you can pass to the function:
- Variables
- The result of
new
- References returned from functions
In the specific case, since you are using a function that is not returning a reference, you can only use a variable to store the result of node_show()
, and pass that variable to render()
or drupal_render()
.
Notice that, in 5.5.31 (and maybe also PHP 5.4), the Strict warning: Only variables should be passed by reference is not returned from the following code, which works as if test_array_print()
obtained a reference.
function test_array_print(&$ref) {
$ref[] = 10;
print_r($ref);
}
function test_array() {
return [3, 34];
}
test_array_print(test_array());
It prints the following.
Array
(
[0] => 3
[1] => 34
[2] => 10
)
Still, see what Passing by Reference says:
No other expressions should be passed by reference, as the result is undefined. For example, the following examples of passing by reference are invalid:
<?php
function foo(&$var)
{
$var++;
}
function bar() // Note the missing &
{
$a = 5;
return $a;
}
foo(bar()); // Produces fatal error as of PHP 5.0.5, strict standards notice
// as of PHP 5.1.1, and notice as of PHP 7.0.0
foo($a = 5); // Expression, not variable
foo(5); // Produces fatal error
?>
注释
评论#1
gaas 信用归因: gaas评论评论#2
steinmb 信用归因: steinmb评论已经在dev中解决了 PLS。测试与最新的开发。如果问题仍然存在,重新打开。
评论#3
amanire 信用归因: amanire评论我很想看到这个修复程序进入稳定版本。我不想在生产站点上使用开发分支或修补模块。有什么办法可以帮忙吗?
评论#4
没有Sssweat 信用归因:没有Sssweat评论所有的警告是说,你需要传递/使用一个变量。所以你要做的就是创建一个变量并使用它。
只需用以下两行替换第132行
评论#5
没有Sssweat 信用归因:没有Sssweat评论评论#6
edachan 信用归因: edachan评论#4工作完美,感谢camster!
评论#7
drupov 信用归因: drupov评论重复的https://www.drupal.org/node/1717470
评论#8
bigferumdron 信用归因: bigferumdron评论请在稳定版本中修复此错误。Мany人害怕使用dev版本。谢谢。
来自 https://www.drupal.org/node/2194237