Type hinting also works if class implements interface

Hi,

I’m trying to understand why when a class implements an interface it can be used just like hinting for a class.

IE:


interface FooInterface {}

class Foo implements FooInterface {}
class Boz implements FooInterface {}

class Bar {

  public function check(FooInterface $fi) {} // will work for Foo and Boz class
}

Why does this work? Although they implement the same interface an object may not have a method if it is called.

You use an interface when you want a public method to be implemented. So when an object is passed that implements a certain interface that another object method expects it knows that method will be there. If the interface defines no methods, why have an interface?