PHP 致命错误:调用时传递引用已被删除
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19804573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP Fatal error: Call-time pass-by-reference has been removed
提问by Anton
I have an oldish script and lately I get this error:
我有一个古老的脚本,最近我收到了这个错误:
Fatal error: Call-time pass-by-reference has been removed in /****/******/public_html/****/cp-list-summary.php on line 100
And it looks like this around line 100 on that file:
它看起来像该文件的第 100 行左右:
if ($row[images])
{
$image_set = array ();
$result = mysql_query ('SELECT fname FROM ' . $dbimgs . ' WHERE listid=\'' . $_GET['id'] . '\' ORDER BY id ASC', $link);
while ($images = mysql_fetch_array ($result))
{
array_push (&$image_set, $images[fname]);
}
}
What causes the error and how to fix it? I'm not a developer, so please take it slow.
是什么导致错误以及如何修复它?我不是开发人员,所以请慢慢来。
回答by Pascal
Looks like you site php has being upgraded or you are reusing code from < php 5.3
看起来您的网站 php 已升级,或者您正在重用 < php 5.3 中的代码
Simply remove the &on (&$image
只需删除&(&$image
Note: There is no reference sign on a function call - only on function definitions. Function definitions alone are enough to correctly pass the argument by reference. As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.
注意:函数调用没有引用符号——仅在函数定义上。仅函数定义就足以通过引用正确传递参数。从 PHP 5.3.0 开始,当您在 foo(&$a); 中使用 & 时,您将收到一条警告,指出“调用时传递引用”已被弃用。从 PHP 5.4.0 开始,调用时传递引用被删除,因此使用它会引发致命错误。
No other expressions should be passed by reference, as the result is undefined.
不应通过引用传递其他表达式,因为结果未定义。
回答by hjpotter92
You are trying to pass a pointer to your array in array_push
. That is why the fatal error is encountered. Simply use:
您正在尝试将指向数组的指针传递给array_push
. 这就是遇到致命错误的原因。只需使用:
array_push( $image_set, $images[fname] );
Note:
array_push()
will raise a warning if the first argument is not an array.
注意:
array_push()
如果第一个参数不是数组,则会引发警告。
回答by yarzombo
Enter to Joomla root directory and execute:
进入Joomla根目录并执行:
find ./ -type f -name "*.php" -exec sed -i 's/\&$/$/g' {} +
This works for me.
这对我有用。