PHP 7.1无法识别PHP5.6 +语法`use function'

时间:2018-07-23 05:31:20

标签: php apache

我有一个在Apache和PHP 7.1上运行的PHP网站。 该应用程序在我的PC上运行良好,当我部署到服务器时,出现以下错误:

PHP Parse error: syntax error, unexpected 'function' (T_FUNCTION), expecting identifier (T_STRING) or \\\\ (T_NS_SEPARATOR)

当我查看错误发生的位置时,据我了解,它是PHP5.6 +语法:

use function ...;

当我运行php --versionwhich php时,表明它是PHP 7.1。 是否有设置将php配置为允许特定版本以上的语法?

编辑: phpinfo()报告PHP 5.5.9 我想我需要的是有关如何设置Apache以使用默认PHP版本(在服务器为7.1的情况下)的帮助。

2 个答案:

答案 0 :(得分:0)

答案是禁用PHP 5模块并为apache启用7.1:

sudo a2dismod php5
sudo a2enmod php7.1
sudo service apache2 restart

答案 1 :(得分:-2)

use keywork will support all version of php. i think your function declaration error. 
you can use below example and correct your function
**use** can only be used with anonymous functions. Using it with named functions 
 gives a syntax error.

 <?
function counter($start) {
  $value = $start;

 return function() use (&$value) {
   return $value++;
 };

}

 $counter = counter(6);

echo $counter() . "\n";
echo $counter() . "\n";