3v4l.org

run code in 300+ PHP versions simultaneously
<?php class A {} class B {} class C extends A {} $tests = [ 1 => [new A(), new A()], // succeeds 2 => [new A(), new B()], // fails 3 => [new C(), new C()], // succeeds ]; echo 'TEST 1:' . PHP_EOL; foreach ($tests as $index => $collection) { try { array_map(static function (A $object): void {}, $collection); } catch (\TypeError $e) { echo sprintf('Index %d failed, because it doesn\'t contain instances of A only.' . PHP_EOL, $index); } } echo PHP_EOL; echo 'TEST 2:' . PHP_EOL; foreach ($tests as $index => $collection) { try { array_map(static function (C $object): void {}, $collection); } catch (\TypeError $e) { echo sprintf('Index %d failed, because it doesn\'t contain instances of C only.' . PHP_EOL, $index); } }
Output for git.master, git.master_jit, rfc.property-hooks
TEST 1: Index 2 failed, because it doesn't contain instances of A only. TEST 2: Index 1 failed, because it doesn't contain instances of C only. Index 2 failed, because it doesn't contain instances of C only.

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:
184.4 ms | 406 KiB | 5 Q