Abstract Methods in php

Abstract Methods in PHP also provides a mechanism for declaring that certain methods on the class must be implemented by subclasses—the implementation of those methods is not defined in the parent class. In these cases, you provide an abstract method; in addition, if a class has any methods in it defined as abstract, you must also declare the class as an abstract class:

abstract class Component
{
 abstract function printOutput();
}
class ImageComponent extends Component
{
function printOutput()
 {
 echo "Pretty picture";
 }
}

Abstract classes cannot be instantiated. Also note that unlike some languages, you cannot provide a default implementation for abstract methods.

Leave a Comment