I suppose this could apply to any dynamic language, but the one I\'m using is JavaScript. We have a situation where we\'re writing a couple of controls in JavaScript that need t
This is the same for PHP; you don't really need interfaces. But they exist for architectural needs. In PHP, you can specify type hints for functions which can be useful.
Second, an interface is a contract. It's a formal contract that all objects from this interface have those functions. Better to ensure that your classes meet those requirements than to remember: "mm, this class has isEnabled()
but the other one is checkIfEnabled()
". Interfaces help you to standardise. Others working on the derived object don't have to check whether the name is isEnabled
or checkIfEnabled
(better to let the interpreter catch those problems).