Abstract Keyword¶
PHP has abstract classes, properties and methods. Classes defined as abstract cannot be instantiated, and any class that contains at least one abstract method, or property hook, must also be abstract.
<?php
abstract class AbstractClass
{
// Force Extending class to define this method
abstract protected function getValue();
abstract protected function prefixValue($prefix);
// abstract property
abstract public $p { get; }
// Common method
public function printOut() {
print $this->getValue() . "\n";
}
}
?>
See also Interfaces vs Abstract Classes in PHP, Testing Abstract Classes in PHP using Anonymous Classes and Why (nearly) every PHP class you write should be abstract or final.
Related : Final Keyword, Abstraction, Concrete Class, Object, Overriding