我有以下代码:PHP 7:通过引用传递非变量以及为什么通知如果函数通过,但是如果数组通过时发生致命错误?
$family = cis_resempty(wp_get_post_terms($post->ID,'family'),0);
我收到以下错误:
Notice: Only variables should be passed by reference in C:\xampp.....xxx.php on line 18
如果我做了以下内容:
$family = cis_resempty(array('a'),0);
我甚至得到
Fatal error: Only variables can be passed by reference in C:\xampp...xxx.php on line 16
功能cis_resempty是这样的(但其从库):
function cis_resempty(&$var,$key) { ... }
发现,如果我删除cis_resempty的参数列表中的&
符号没有错误。
如果我这样做:
$family = @cis_resempty(wp_get_post_terms($post->ID,'family'),0);
没有通知,一切工作 - 但Netbeans的说:
Misuse of the error control operator
但是,如果我这样做:
$family = @cis_resempty(array('a'),0);
致命错误仍然存在。
为什么我可以通过引用传递一个函数,并使用错误控制运算符来抑制通知,但是如果我传递一个数组,我会得到一个致命错误?
为什么通过引用传递非变量很糟糕?