Just a clarification from an earlier question about OO PHP. I’ve checked on the php.net website but still not completely sure. Should be a quick answer, I expect.
When ‘defining’ methods in an interface, must the class that implements it use all the listed methods from the interface?
Example:
interface foo {
public function blah();
public function de();
public function bleh();
}
class bar implements foo {
public function blah() {
//Code here
}
public function bleh() {
//More code here
}
}
Would that work?
No. A class implementing an interface must implement all methods defined by the interface or be defined abstract. If you try to run the script without all methods defined you’ll get
In other words, either do
or
or leave some methods empty in the concrete class