3v4l.org

run code in 500+ PHP versions simultaneously
<?php declare(strict_types=1); error_reporting(E_ALL); final class foo { public function __toString(): string { return 'asdas'; } } function bar (string|\Stringable $c) { var_dump((string)$c); } bar(new foo());
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.36, 8.3.0 - 8.3.37, 8.4.1 - 8.4.28, 8.5.0 - 8.5.13, 8.6.0
string(5) "asdas"
Output for 7.4.0 - 7.4.33
Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in /in/3FKKQ on line 16
Process exited with code 255.

preferences:
21.94 ms | 1167 KiB | 6 Q