php - 当表达式作为闭包内数字数组的索引传递时,为什么PHP会抛出错误
问题描述
我有一个在 Ubuntu 上运行 Apache2、PHP7.4 的开发环境和一个在 Ubuntu 上运行 Apache2、PHP7.2 的生产服务器。以下代码在我的开发环境中运行良好,但在生产环境中失败并出现错误[2020-07-25 13:00:16] production.ERROR: syntax error, unexpected '[', expecting ']' {"exception":"[object] (ParseError(code: 0): syntax error, unexpected '[', expecting ']' at /path/to/file.php:133)
。这是失败的行:$month = $months[$months[$i - 1]];
。
function myFunction(){
$months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec'];
return (function()use($months){
$ret = [];
$i = 1;
while($i < 13)
{
$month = $months[$i - 1];
// some more code that updates $ret ...
$i++;
}
return $ret;
})();
}
我会感谢任何关于为什么失败的想法。
解决方案
推荐阅读
- python-3.x - SQLite 选择在 12 次查询后停止工作
- javascript - 有人可以解释这里发生的步骤流程吗?
- html - 为什么边框与内容不对齐?
- sql - 连续 + 和 - 的意外结果
- java - 为什么我们在这里将 Font.PLAIN 分配给像 valBold 这样的 int 值?java中的字体是整数吗?
- reactjs - 如何使用 react-router 制作动态路由?
- c# - Newtonsoft Json 序列化程序在使用 CamelCasePropertyNamesContractResolver 时出现 NullReferenceException
- powershell - 通过 SSL 进行 PowerShell 远程处理的第二个跃点
- node.js - 如何使用 express 将表单数据从 React App 发布到后端?
- r - R:pglm 包(sigma 系数)