0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP の各バージョンを検証するための docker-compose

Last updated at Posted at 2021-12-23

PHPのアップグレードのために細かい動作を確認したくて、
1つの docker-compose に検証用環境全部詰め込んでみました

検証用の docker-compose ファイル

docker-composel.yml
version: '3'
services:
  php-8.1:
    image: "php:8.1-cli"
    stdin_open: true
  php-8.0:
    image: "php:8.0-cli"
    stdin_open: true
  php-7.4:
    image: "php:7.4-cli"
    stdin_open: true
  php-7.3:
    image: "php:7.3-cli"
    stdin_open: true
  php-7.2:
    image: "php:7.2-cli"
    stdin_open: true

ファイルはこれだけ
stdin_open: true をつけているので実行プロセスが特になくてもコンテナが終了せず利用できます

inspect_php
- docker-compose.yml

実行

まとめて立ち上げてみます

$ cd inspect_php
$ docker-compose up
...
Attaching to study_php_php-7.4_1, study_php_php-8.0_1, study_php_php-8.1_1, study_php_php-7.2_1, study_php_php-7.3_1
php-7.4_1  | Interactive shell
php-7.4_1  | 
php-8.0_1  | Interactive shell
php-8.0_1  | 
php-8.1_1  | Interactive shell
php-8.1_1  | 
php-7.3_1  | Interactive shell
php-7.3_1  | 
php-7.2_1  | Interactive shell
php-7.2_1  | 

7.2から8.1まで起動しました
それぞれのバージョンも確認

$ docker-compose exec php-7.2 /bin/sh -c 'php -v'
PHP 7.2.34 (cli) (built: Dec 11 2020 10:44:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

$ docker-compose exec php-7.3 /bin/sh -c 'php -v'
PHP 7.3.33 (cli) (built: Dec 21 2021 22:01:38) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.33, Copyright (c) 1998-2018 Zend Technologies

$ docker-compose exec php-7.4 /bin/sh -c 'php -v'
PHP 7.4.27 (cli) (built: Dec 21 2021 21:28:03) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

$ docker-compose exec php-8.0 /bin/sh -c 'php -v'
PHP 8.0.14 (cli) (built: Dec 21 2021 20:34:57) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.14, Copyright (c) Zend Technologies

$ docker-compose exec php-8.1 /bin/sh -c 'php -v'
PHP 8.1.1 (cli) (built: Dec 21 2021 19:35:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies

大丈夫ですね
折角動いたのでバージョンごとの動きの違いも見てみましょう

検証

https://www.php.net/manual/ja/migration80.incompatible.php
PHP7.4 -> PHP8.0 で文字列と数値の比較に変更があったので試してみます

PHP 7.4

$ docker-compose exec php-7.4 /bin/sh
# php -a
Interactive shell

php > var_dump(0 == "");
bool(true)

7.4 では 0 と非数値文字列の比較は true になります

PHP 8.0

$ docker-compose exec php-8.0 /bin/sh
# php -a
Interactive shell

php > var_dump(0 == "");
bool(false)

8.0 では false になることが確認できました

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?