PHP 的列表函数如何工作?

发布于 2024-09-24 02:49:20 字数 321 浏览 0 评论 0原文

最近在这里回答了几个涉及使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦中楼上月下 2024-10-01 02:49:20

list 是一个语言构造,而不是一个函数。它不遵循普通函数的规则,它更类似于 iffor (或 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 an if or for (or array(), as the manual states), hard-coded into the PHP core.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文