PHP 的列表函数如何工作?
最近在这里回答了几个涉及使用 PHP 的 list
函数的问题后,我想知道,“这个函数到底是如何在幕后工作的?”。我正在考虑使用 func_get_args()
,然后迭代参数列表,这一切都很好,但是赋值部分到底是如何工作的?
list(...) = array($x, $y, $z);
这不是首先评估的吗?
因此,准确地说,我的问题是 list
函数如何创建分配给尚未评估的数组的作用域变量?
After recently answering a couple of questions here on SO that involved utilizing PHP's list
function, I wondered, "how in the world does that function actually work under the hood?". I was thinking about something like using func_get_args()
and then iterating through the argument list, and that's all nice and peachy, but then how in the world does the assignment part work?
list(...) = array($x, $y, $z);
isn't this ^ evaluated first?
So to be precise, my question is how is the list
function able to create scoped variables which get assigned to the not-yet evaluated array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
list
是一个语言构造,而不是一个函数。它不遵循普通函数的规则,它更类似于if
或for
(或array()
,如手册所述),硬编码到 PHP 核心中。list
is a language construct, not a function. It does not play by the rules of normal functions, it's more akin to anif
orfor
(orarray()
, as the manual states), hard-coded into the PHP core.