Abstract Keyword¶
PHP has abstract classes and methods. Classes defined as abstract cannot be instantiated, and any class that contains at least one abstract method must also be abstract.
<?php
abstract class AbstractClass
{
// Force Extending class to define this method
abstract protected function getValue();
abstract protected function prefixValue($prefix);
// Common method
public function printOut() {
print $this->getValue() . "\n";
}
}
?>
See also Interfaces vs Abstract Classes in PHP, Abstract classes and methods, Testing Abstract Classes in PHP using Anonymous Classes
Related : Final Keyword