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 git.master, git.master_jit, rfc.property-hooks

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
51.65 ms | 401 KiB | 8 Q