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 *.
