3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Foo { class Bar { }; } namespace { use Foo\Bar; class_alias(Bar::class, 'FooBar'); class FooBar {}; class GuineaPig { public function withNamespace(Bar $bar) { echo sprintf("Passing %s worked with %s\n", get_class($bar), __METHOD__); } public function withoutNamespace(FooBar $bar) { echo sprintf("Passing %s worked with %s\n", get_class($bar), __METHOD__); } } $bar = new Bar(); $foobar = new FooBar(); $pig = new GuineaPig(); $pig->withNamespace($bar); $pig->withoutNamespace($foobar); $pig->withNamespace($foobar); $pig->withoutNamespace($bar); }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Warning: Cannot declare class FooBar, because the name is already in use in /in/kBsXT on line 13 Passing Foo\Bar worked with GuineaPig::withNamespace Passing FooBar worked with GuineaPig::withoutNamespace Fatal error: Uncaught TypeError: GuineaPig::withNamespace(): Argument #1 ($bar) must be of type Foo\Bar, FooBar given, called in /in/kBsXT on line 35 and defined in /in/kBsXT:18 Stack trace: #0 /in/kBsXT(35): GuineaPig->withNamespace(Object(FooBar)) #1 {main} thrown in /in/kBsXT on line 18
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Warning: Cannot declare class FooBar, because the name is already in use in /in/kBsXT on line 13 Passing Foo\Bar worked with GuineaPig::withNamespace Passing FooBar worked with GuineaPig::withoutNamespace Fatal error: Uncaught TypeError: GuineaPig::withNamespace(): Argument #1 ($bar) must be of type Foo\Bar, FooBar given, called in /in/kBsXT on line 35 and defined in /in/kBsXT:18 Stack trace: #0 /in/kBsXT(35): GuineaPig->withNamespace(Object(FooBar)) #1 {main} thrown in /in/kBsXT on line 18
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Cannot declare class FooBar, because the name is already in use in /in/kBsXT on line 13 Passing Foo\Bar worked with GuineaPig::withNamespace Passing FooBar worked with GuineaPig::withoutNamespace Fatal error: Uncaught TypeError: Argument 1 passed to GuineaPig::withNamespace() must be an instance of Foo\Bar, instance of FooBar given, called in /in/kBsXT on line 35 and defined in /in/kBsXT:18 Stack trace: #0 /in/kBsXT(35): GuineaPig->withNamespace(Object(FooBar)) #1 {main} thrown in /in/kBsXT on line 18
Process exited with code 255.

preferences:
218.85 ms | 402 KiB | 181 Q