[PHPComptibilityを使って、PHP7.4のコードからPHP8.1までの互換性を調査してみた]
環境: M1 MacBook
-
ローカルPCにPHP 8.2以上をインストールする(PHP8.2以上の未インストール者 初回のみ)
brew install shivammathur/php/php@8.2
-
~/.zshrc にインストールしたPHPのパスを指定する (PHP8.2以上の未インストール者 初回のみ)
vi ~/.zshrc
-- ここから --
export PATH="/usr/local/opt/php@8.2/bin:$PATH"
-- ここまで -- -
composerのインストール (composerの未インストール者 初回のみ)
[インストール]
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
[実行ファイル配置]
sudo mv composer.phar /usr/local/bin/composer
-
簡易composer.jsonの作成 (composer.jsonが無い場合 初回のみ)
composer init --quiet --name=my_vendor/my-package --description="My description" --license=MIT
-
PHP8.0以上の互換性を検知するphpcompatibilityをインストールする (phpcompatibilityの未インストール者 初回のみ)
composer require --dev phpcompatibility/php-compatibility dev-develop
-
PHPCompatibilityを実行して互換性を洗い出す
[任意で設定する内容]
互換性対象場所: . ※現在のディレクトリ以下の全ファイル
互換性対象バージョン: 8.1
使用するメモリ: 512M ※メモリ不足だった場合は適度に増やすこと
出力レポート名: PHPCompatibility_8.1_report.txt
[cui実行例]
./vendor/bin/phpcs -p . --standard=PHPCompatibility --runtime-set testVersion 8.1 -d memory_limit=512M --report-full=PHPCompatibility_8.1_report.txt
[結果例]
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 23 ERRORS AND 2 WARNINGS AFFECTING 24 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 | ERROR | Function name, class name, namespace name or constant name can not be reserved keyword 'match' (since version 8.0)
11 | ERROR | 'mixed' is a soft reserved keyword as of PHP version 7.0 and a reserved keyword as of PHP version 8.0 and should not be used to name a class, interface or trait or as part of a namespace
| | (class declaration)
19 | ERROR | The real cast is deprecated since PHP 7.4 and removed since PHP 8.0; Use (float) instead
20 | ERROR | The unset cast is deprecated since PHP 7.2 and removed since PHP 8.0; Use unset() instead
24 | ERROR | The variable '$php_errormsg' is deprecated since PHP 7.2 and removed since PHP 8.0; Use error_get_last() instead
27 | ERROR | Specifying an autoloader using an __autoload() function is deprecated since PHP 7.2 and no longer supported since PHP 8.0
31 | ERROR | Function create_function() is deprecated since PHP 7.2 and removed since PHP 8.0; Use an anonymous function instead
36 | ERROR | Function each() is deprecated since PHP 7.2 and removed since PHP 8.0; Use a foreach loop or ArrayIterator instead
100 | ERROR | The "hour" parameter for function mktime() is missing. Passing this parameter is no longer optional. The optional nature of the parameter is deprecated since PHP 5.1 and removed since
| | PHP 8.0
103 | ERROR | The "hour" parameter for function gmmktime() is missing. Passing this parameter is no longer optional. The optional nature of the parameter is removed since PHP 8.0
163 | WARNING | Function enchant_broker_free_dict() is deprecated since PHP 8.0; Use unset the object instead
164 | WARNING | Function enchant_broker_free() is deprecated since PHP 8.0; Use unset the object instead
171 | ERROR | Function read_exif_data() is deprecated since PHP 7.2 and removed since PHP 8.0; Use exif_read_data() instead
183 | ERROR | The constant "FILTER_FLAG_SCHEME_REQUIRED" is deprecated since PHP 7.3 and removed since PHP 8.0
183 | ERROR | The constant "FILTER_FLAG_HOST_REQUIRED" is deprecated since PHP 7.3 and removed since PHP 8.0
200 | ERROR | Function image2wbmp() is deprecated since PHP 7.3 and removed since PHP 8.0; Use imagewbmp() instead
202 | ERROR | Function jpeg2wbmp() is deprecated since PHP 7.2 and removed since PHP 8.0; Use imagecreatefromjpeg() and imagewbmp() instead
204 | ERROR | Function png2wbmp() is deprecated since PHP 7.2 and removed since PHP 8.0; Use imagecreatefrompng() or imagewbmp() instead
230 | ERROR | Function gmp_random() is deprecated since PHP 7.2 and removed since PHP 8.0; Use gmp_random_bits() or gmp_random_range() instead
265 | ERROR | Function imap_header() is removed since PHP 8.0; Use imap_headerinfo() instead
278 | ERROR | The constant "INTL_IDNA_VARIANT_2003" is deprecated since PHP 7.2 and removed since PHP 8.0
412 | ERROR | The Mbstring regex "e" modifier is deprecated since PHP 7.1 and removed since PHP 8.0. Use mb_ereg_replace_callback() instead (PHP 5.4.1+).
429 | ERROR | The "is_hex" parameter for function mb_decode_numericentity() is removed since PHP 8.0
479 | ERROR | The "cipher_algo" parameter for function openssl_seal() is missing. Passing this parameter is no longer optional. The optional nature of the parameter is removed since PHP 8.0
485 | ERROR | The "cipher_algo" parameter for function openssl_open() is missing. Passing this parameter is no longer optional. The optional nature of the parameter is removed since PHP 8.0
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------