|
One other use of interfaces I forgot to mention is that your program can check to see if an object implements a particular interface in the same way that it can ask that object what class it is (or is descended from).
If an object implements the FooBar interface, then your code can check that it does by using ($object instanceof FooBar). The result will be true or false.
The same check can be made at runtime when the function is called:
function your_function(FooBar $object)
{
....
}
and if $object doesn't implement the FooBar interface, then when your_function() is called, PHP will whinge.
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Last edited by Weedpacket; 09-09-2004 at 04:59 AM.
|