Interface
- Using interfaces, you can specify which methods a class must implement, but you do not need to define the specific content of these methods.
- Interfaces are defined by the interface keyword, just like defining a standard class, but all methods defined are empty.
- All methods defined in an interface must be public, which is a feature of the interface.check here
- To implement an interface, the implements operator must be use. All methods defined in the interface must be implemented in the class, otherwise a fatal error will be reported. Classes can implement multiple interfaces and use commas to separate the names of multiple interfaces.
Abstract class
- Any class, if at least one of its methods is declared abstract, must be declared abstract.
- Classes defined as abstract cannot be instantiated.check here
- A method defined as abstract simply declares its invocation (parameters) and cannot define its specific functional implementation.
- When inheriting an abstract class, the subclass must define all abstract methods in the parent class; moreover, access control of these methods must be the same as in the parent class.
Static
- Declaring the class attribute or method with static keyword allows direct access without instantiating the class.
- Static attributes cannot be accessed through a class of instantiated objects (but static methods can).
- Because static methods do not need to be invoked through objects, the pseudo-variable $this is not available in static methods.
- Static attributes cannot be accessed by objects through the – > operator.
Final
PHP 5 adds a final keyword. If the method in the parent class is declared final,check here the subclass cannot override the method. If a class is declared final, it cannot be inherited. For example:
<?phpclass BaseClass { public function test() { echo “BaseClass::test() called” . PHP_EOL; } final public function moreTesting() { echo “BaseClass::moreTesting() called” . PHP_EOL; }}class ChildClass extends BaseClass { public function moreTesting() { echo “ChildClass::moreTesting() called” . PHP_EOL; }}//Fatal error: Cannot override final method BaseClass::moreTesting()?>