This is one use of interfaces. If you want to be sure that the object has a ->foobar($baz) method, you could expect an interface:
interface iFooBar {
public function foobar($baz);
}
class Foo implements iFooBar {
public function foobar($baz) { echo $baz; }
}
class Bar implements iFooBar {
public function foobar($baz) { print_r($baz); }
}
function doSomething(iFooBar $foo) {
$foo->foobar('something');
}
Then, when calling, these will work:
doSomething(new Foo());
doSomething(new Bar());
These will not:
doSomething(new StdClass());
doSomething('testing');