如何通过引用错误解决此问题?

时间:2013-04-28 04:48:01

标签: php drupal warnings

这是drupal模块的一部分,我收到了这个错误:

Strict warning: Only variables should be passed by reference in customheaderimage_get_last_argument()

我的代码是

function customheaderimage_get_last_argument() {
  return customheaderimage_dashtoslash(array_pop(explode('/', $_GET['q'])));
}

q包含类似“admin / configure / customheaderimage / edit / node - 2”的值,dashtoslash将 - 更改为str_replace的斜杠。因此,所有这些链接函数都会返回类似'node / 2'的内容,并且它目前正在运行。只是抛出这个警告

如何在几个地方解决此警告消息?

1 个答案:

答案 0 :(得分:2)

array_pop()通过引用引用一个参数:

  

mixed array_pop(array& $ array)

它需要引用,因为它修改了作为参数传入的数组。您传递函数的结果而不是变量,因此引用没有意义。换句话说,您需要传递一个变量作为参数。

function customheaderimage_get_last_argument() {
  $arr = explode('/', $_GET['q']);
  return customheaderimage_dashtoslash(array_pop($arr));
}