解决办法:升级php版本

Fatal error: strict_types declaration must be the very first statement in the script in *.php on line *
Parse error: syntax error, unexpected ‘declare’ (T_DECLARE) in *.php on line *

 

PHP强类型是从PHP 7.0开始支持的,使用declare(strict_types=1)来声明脚本中的函数调用使用强类型变量及返回值,declare(strict_types=1)必须作为脚本的第一句PHP代码,如果定义函数的脚本中使用了declare(strict_types=1),而调用函数的脚本中没有使用,强类型声明无效,强类型声明只影响函数调用有,对其他语法没有影响,在declare(strict_types=1)以后,false == 0 == ” == null == array() 1 == true 之类的表达式仍然成立。

不能在declare(strict_types=1)前使用@,写作@declare(strict_types=1);否则会报错Parse error: syntax error, unexpected ‘declare’ (T_DECLARE) in *.php on line *.

如果declare(strict_types=1);不是所在PHP脚本文件中的第一句有效的PHP代码,会报错Fatal error: strict_types declaration must be the very first statement in the script in *.php on line *.

如果PHP版本低于7.0.0,会报错Warning: Unsupported declare ‘strict_types’ in *.php on line *.

分类: PHP