PHP相容性檢查,PHP升級語法檢查
阿新 • • 發佈:2018-12-26
當我們進行PHP版本升級的時候,比如從5.x升級到7.x會遇到專案程式碼不相容的情況。如果通過人工檢查,工作量比較大,我們可以使用PHPCompatibility+PHP_CodeSniffer進行相容性檢查。
1)先安裝PHP_CodeSniffer,建議使用composer安裝
composer global require "squizlabs/php_codesniffer=*"
2)安裝PHPCompatibility
這裡建議使用下載zip包的方式,因為PHPCompatibility僅僅作為PHP_CodeSniffer的外掛使用。
Download the latest PHPCompatibility release and unzip/untar it into an arbitrary directory.
phpcs --config-set installed_paths /path/to/PHPCompatibility
3)執行相容性檢查
phpcs --standard=PHPCompatibility [path]
執行的結果如下:可以看到檔名,不相容的line。
FILE: Crypt.php
----------------------------------------------------------------------
FOUND 15 ERRORS AFFECTING 8 LINES
----------------------------------------------------------------------
30 | ERROR | The constant "MCRYPT_RIJNDAEL_256" is deprecated since
| | PHP 7.1 and removed since PHP 7.2