首页 > Web开发 > 详细

PHP Warning: Unsupported declare 'strict_types' in ...

时间:2020-07-10 17:05:44      阅读:528      评论:0      收藏:0      [点我收藏+]

 

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 Warning: Unsupported declare 'strict_types' in ...

原文:https://www.cnblogs.com/yimingwang/p/13279706.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!