[英]PHP Version 5.2.14 / Parse error: syntax error, unexpected T_FUNCTION, expecting ')'
I have a certain piece of code that I'm trying to use with PHP Version 5.2.14 . 我有一些要与PHP 5.2.14一起使用的代码。 Is it incompatible??
它不兼容吗? I run the following,
我运行以下命令
jailshell-3.2$ php -l /XYZ/functions.php
And it gives: 它给出:
Parse error: syntax error, unexpected T_FUNCTION, expecting ')' in /XYZ/functions.php on line 2115 Errors parsing /XYZ/functions.php
解析错误:语法错误,意外的T_FUNCTION,在/XYZ/functions.php的2115行中出现')'解析/XYZ/functions.php的错误
The code is: 代码是:
2114 $range = array_map(
2115 function (DatePeriod $p) use ($vt2) {
2116 $res = array();
Your code uses anonymous functions
which were supported in PHP 5.3. 您的代码使用PHP 5.3支持的
anonymous functions
。 So, you need PHP 5.3 to get it to working. 因此,您需要PHP 5.3才能使其正常工作。 Upgrade your server's PHP installation.
升级服务器的PHP安装。
Anonymous functions, also known as closures, allow the creation of functions which have no specified name. 匿名函数(也称为闭包)允许创建没有指定名称的函数。
You are using anonymous functions which are available since PHP 5.3.0 . 您正在使用从PHP 5.3.0开始可用的匿名函数 。
To resolve this you can upgrade your PHP as suggested in other answer. 要解决此问题,您可以按照其他答案中的建议升级PHP。
Alternatively you can define the function outside array_map
and then use that function name in the call to array_map
或者,您可以在
array_map
之外定义函数,然后在对array_map
的调用中使用该函数名称
From the php manual on Anonymous Functions : 从有关匿名函数的php手册中:
Note: Anonymous functions are available since PHP 5.3.0.
注意:自PHP 5.3.0起,匿名函数可用。
prior to 5.3.0, do it like this: 在5.3.0之前,请按以下步骤操作:
$range = array_map( "name_of_function_to_call", $myArray );
I think the lambda style function is not yet implemented in 5.2 我认为Lambda样式功能尚未在5.2中实现
use create_function or just create the function and pass it the function name in array_map . 使用create_function或仅创建函数并将函数名称传递给array_map 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.