
Originally Posted by
OfficeOfTheLaw
My bad... miscommunication.

No problem. 

Originally Posted by
OfficeOfTheLaw
I find type hinting useful in instances where I have methods that require an object of a certain type, a lot better that testing to see if is an object and of a specific class.
This exact sentence is what should tip you off to my point: your method require an object of a certain type.
Type != class, although in practice thea are usually equivalent. As I said previously, a "type" is defined by its behavior, or rather responsibility: to be of a certain type, an object has to know certain things (i.e. have certain attributes) and to be able to do certain things (i.e. have certain methods) -- in other words, to have a certain public Interface (capital). And some objects may have multiple types.
In static languages, you must specify a class literally; in some, that was replaced by the ability to instead specify a type (i.e. an Interface), but you still have to specify something. In dynamic languages, you don't care of the actual type -- all you need to know whether an object can to do something. Or as an example: when your object enters the water, your program doesn't care whether it's of Fish, Duck, Dolphin, IanThorpe or Submarine class -- all that is important is that it has implemented the method swim(). Even if its implementation goes like this:
PHP Code:
public function swim()
{
$this->drown();
}
Bookmarks