3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); /** * @template T */ class Example { /** @param T $inner */ public function __construct(public mixed $inner) { } /** * @return T */ public function get(): mixed { return $this->inner; } /** * @template U * @param callable(T): U $callback * @return U */ public function map(callable $callback): mixed { return $callback($this->inner); } /** * @template U * @param callable(T): U $callback * @return Example<U> */ public function chainMap(callable $callback): Example { return new self($callback($this->inner)); } } $example = new Example(123); // phpstorm understands this as int|mixed $value = $example->get(); // phpstorm understands this as int|mixed $value = $example->map(fn (int $val): string => (string) $val); function requiresInt(int $input) { } // phpstorm still sees this more crazy one as int|mixed.. $value = $example->chainMap(fn ($val) => (string) $val) ->chainMap(fn ($val) => new Example($val)) ->chainMap(fn ($val) => new Example($val)) ->chainMap(fn ($val) => $val->get()->get()) ->get(); // but psalm understands // psalm: InvalidScalarArgument: Argument 1 of requiresInt expects int, "123" provided requiresInt($value);
Output for 8.1.23 - 8.1.34, 8.2.10 - 8.2.30, 8.3.0 - 8.3.4, 8.3.6 - 8.3.30, 8.4.1 - 8.4.14, 8.4.16 - 8.4.17, 8.5.0 - 8.5.2
Fatal error: Uncaught TypeError: requiresInt(): Argument #1 ($input) must be of type int, string given, called in /in/FlDJZ on line 60 and defined in /in/FlDJZ:48 Stack trace: #0 /in/FlDJZ(60): requiresInt('123') #1 {main} thrown in /in/FlDJZ on line 48
Process exited with code 255.
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.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 Fatal error: Uncaught TypeError: requiresInt(): Argument #1 ($input) must be of type int, string given, called in /in/FlDJZ on line 60 and defined in /in/FlDJZ:48 Stack trace: #0 /in/FlDJZ(60): requiresInt('123') #1 {main} thrown in /in/FlDJZ on line 48
Process exited with code 255.

preferences:
110.68 ms | 409 KiB | 5 Q