<?php interface I {} class A implements I {} class B implements I {} $a = new A(); function doWork(I $i) { $carry = []; // from array_reduce, not relevant [$key, $value] = match (true) { $i instanceof A => ['a', []], // default is not handled //true => ['oops', []], }; $carry[$key] = $value; return $carry; } var_dump(doWork($a));
You have javascript disabled. You will not be able to edit any code.