简体   繁体   English

PHP版本5.2.14 /解析错误:语法错误,意外的T_FUNCTION,期望')'

[英]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.

相关问题 解析错误:语法错误,意外\\'?> \\',期待函数(T_FUNCTION) - Parse error: syntax error, unexpected \'?>\', expecting function (T_FUNCTION) PHP,解析错误:语法错误,意外的T_IF,预期为T_FUNCTION - PHP, Parse error: syntax error, unexpected T_IF, expecting T_FUNCTION PHP解析错误:语法错误,意外的T_STRING,预期的T_FUNCTION - PHP Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION php解析错误:语法错误,意外的T_STRING,在构造上需要T_FUNCTION - php Parse error: syntax error, unexpected T_STRING, expecting T_FUNCTION on construct 语法错误,意外的T_FUNCTION,预期为')' - syntax error, unexpected T_FUNCTION, expecting ')' 解析错误:语法错误,意外的'=',期望在第33行的DB_driver.php中出现T_FUNCTION - Parse error: syntax error, unexpected '=', expecting T_FUNCTION in DB_driver.php on line 33 解析错误:语法错误,意外的T_ELSE,在1834行的/home/filename.html.php中预期为T_FUNCTION - Parse error: syntax error, unexpected T_ELSE, expecting T_FUNCTION in /home/filename.html.php on line 1834 ItemsController.php 第 97 行中的 FatalThrowableError:解析错误:语法错误,文件意外结束,需要函数 (T_FUNCTION) - FatalThrowableError in ItemsController.php line 97: Parse error: syntax error, unexpected end of file, expecting function (T_FUNCTION) Yii解析错误:语法错误,意外的'if'(T_IF),期望的函数(T_FUNCTION) - Yii Parse error: syntax error, unexpected 'if' (T_IF), expecting function (T_FUNCTION) 解析错误:语法错误,意外的“函数”(T_FUNCTION),预计在第319行 - Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting on line 319
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM