<?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";
}