php - 为什么我会收到 "Only variables should be passed by reference"错误?

标签 php variables pass-by-reference

检查这段代码:

$last = end($p = explode('/', $someString));  

收到此通知:

Only variables should be passed by reference

我真的很困惑,因为 $p 是一个变量。

最佳答案

end() 需要一个变量,而不是一个引用。在你的例子中 $p = explode('/', $someString) 不是一个变量,它是一个赋值。作为documentation说:

This array is passed by reference because it is modified by the function. This means you must pass it a real variable and not a function returning an array because only actual variables may be passed by reference.

你应该这样做:

$p = explode('/', $someString);
$last = end($p); 

关于php - 为什么我会收到 "Only variables should be passed by reference"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20776017/

相关文章:

php - codeigniter 意外的模型加载

javascript - Vue.js 访问具有不确定名称的变量

Java方法不改变参数对象

c - 在二叉搜索树中通过引用重定向指针

php比较两个数字

php - Wordpress、PHP - 将图像插入主题主页

php - 如何使用 php 将用户的 facebook 个人资料图片保存到我的域/网站数据中

PHP变量引用和内存使用

c++ - 将函数声明转换为变量定义的简单技巧

c++ - 在 C++ 中使用指针总是不好的吗?