最近開始把公司產品要升級到 php7 (當然,只是先確定可以在 php7 的環境執行,畢竟還有一段路要走)
因為程式眾多,不可能一支一支檢視,所以就找現成的工具囉!
PHP 7 Compatibility Checker: https://github.com/sstalle/php7cc
這個專案是專門用來檢查你的程式是否有不符合 PHP7 語法的,而且可以在 PHP 5.3.3 以上的環境即可執行
相關升級說明
在處理之前,最好把每個版本的升級說明看一下,這樣比較知道哪些可能會有問題喔!
- PHP 5.3.x to PHP 5.4.x: http://php.net/manual/en/migration54.php
- PHP 5.4.x to PHP 5.5.x: http://php.net/manual/en/migration55.php
- PHP 5.5.x to PHP 5.6.x: http://php.net/manual/en/migration56.php
- PHP 5.6.x to PHP 7.0.x: http://php.net/manual/en/migration70.php
安裝 PHP 7 Compatibility Checker
最快的方法當然是透過 Composer 囉
composer global require sstalle/php7cc
使用方式
直接使用 php 執行 php7cc 即可
參數如下:
php7cc [-e|--extensions [EXTENSIONS]] [-x|--except [EXCEPT]] [-l|--level LEVEL] [-r|--relative-paths] [--integer-size INTEGER-SIZE] [--] <paths> (<paths>)...
只要下 php php7cc {path}
就可以列出那些檔案的語法可能有問題了,不過還是要仔細看,有些是警告,不一定需要修正的
> Line 465: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 474: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 486: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 508: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 519: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 530: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 539: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 549: Function argument(s) returned by "func_get_args" might have been modified func_get_args(); > Line 558: Function argument(s) returned by "func_get_args" might have been modified func_get_args();