- var_dump: documentation ( source)
<?php
declare(strict_types=1);
interface I {
public function example();
}
class A implements I {
public function example(): int { return 123; } // compatible with I::example
}
class B extends A {
public function example(): string { return "string"; } // compatible with I::example
}
function accepts_i_expects_any(I $i) {
var_dump($i->example());
}
accepts_i_expects_any(new B); // receives string, no problem
function accepts_a_expects_int(A $a) {
var_dump($a->example());
}
accepts_a_expects_int(new B); // receives string, problem