3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @template T */ class myInvokable { /** @var T */ private $e; /** @param T $e */ public function __construct($e) { $this->e = $e; } /** * @template B * @param callable(T): B $p * @return B */ public function __invoke($p) { return $p($this->e); } } /** * @template T * @psalm-param T $e * @return myInvokable<T> */ function foo($e): callable { return new myInvokable($e); } $_z = foo('foo')(fn (string $a) => strlen($a)); /** @psalm-trace $_z */; var_dump($_z);
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
int(3)
Output for 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '$a' (T_VARIABLE), expecting ')' in /in/EHf6N on line 33
Process exited with code 255.
Output for 7.2.0 - 7.2.34
Parse error: syntax error, unexpected '$a' (T_VARIABLE), expecting ',' or ')' in /in/EHf6N on line 33
Process exited with code 255.

preferences:
78.86 ms | 408 KiB | 5 Q