3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface Runnable { public function run(string $details): void; } abstract class RunnableBase implements Runnable { public function run(string $more): void { echo $more . "\n"; } } class Impl1 extends RunnableBase { public function run(string $extra): void { parent::run($extra); } } class Impl2 extends RunnableBase { public function run(string $other): void { parent::run($other); } } function getRunnable(): Runnable { if (time() % 2) { return new Impl1(); } else { return new Impl2(); } } $a = getRunnable(); try { // This is the only name that is known at compile time and what I would expect to work. $a->run(details: 'details'); } catch (Throwable $e) { echo $e->getMessage() . "\n"; } try { // I wouldn't expect this to work as it's just an implementation detail. $a->run(more: 'more'); } catch (Throwable $e) { echo $e->getMessage() . "\n"; } try { // I would absolutely never expect this to work, because it is -random-. $a->run(extra: 'extra'); } catch (Throwable $e) { echo $e->getMessage() . "\n"; } try { // I would absolutely never expect this to work, because it is -random-. $a->run(other: 'other'); } catch (Throwable $e) { echo $e->getMessage() . "\n"; }
Output for 8.0.0 - 8.0.17, 8.1.0 - 8.1.4
Unknown named parameter $details Unknown named parameter $more Unknown named parameter $extra other
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.28
Parse error: syntax error, unexpected ':', expecting ')' in /in/P2XSm on line 38
Process exited with code 255.
Output for 7.2.0 - 7.2.34
Parse error: syntax error, unexpected ':', expecting ',' or ')' in /in/P2XSm on line 38
Process exited with code 255.

preferences:
37.8 ms | 408 KiB | 5 Q