3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface HasMethodReturnIntOrString { public function methodA(): int|string; } interface HasMethodReturnIntOrFloat { public function methodA(): int|float; } /** * 返り値が int|string 型であるメソッド methodA の実装を約束するインターフェイスと * 返り値が int|float 型であるメソッド methodA の実装を約束するインターフェイスの * 両方を実装するクラス */ class HasMethodReturnInt implements HasMethodReturnIntOrString, HasMethodReturnIntOrFloat { /** * 返り値が int|string 型 と int|float 型の両方を満たすメソッド * つまり (int|string) & (int|float) の計算結果である int 型の値を返すメソッド * @return int */ public function methodA(): int { return 0; } // 片方の型を満たせない場合↓の様にPHPがエラーを出力します // Fatal error: Declaration of HasMethodReturnInt::methodA(): string must be compatible with HasMethodReturnStringOrFloat::methodA(): int|float in ***\tmp.php on line 28 // public function methodA(): string|int // { // return 0; // } }
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14, 8.5.0
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected '|', expecting ';' or '{' in /in/9MjGI on line 5
Process exited with code 255.

preferences:
49.48 ms | 408 KiB | 5 Q