<?php
ini_set('display_errors', "1");
//create abstract method
abstract class AbstractClass {
public function getValue();
// Common method
public function printOut() {
print $this->getValue() . "\n";
}
}
//extend ConcreteClass1 with AbstractClass
class ConcreteClass1 extends AbstractClass {
public function getValue() {
return "ConcreteClass1";
}
public function prefixValue($prefix) {
return "{$prefix}ConcreteClass1";
}
}
//extend ConcreteClass2 with AbstractClass
class ConcreteClass2 extends AbstractClass {
public function getValue() {
return "ConcreteClass2";
}
public function prefixValue($prefix) {
return "{$prefix}ConcreteClass2";
}
}
//create object of ConcreteClass1
$class1 = new ConcreteClass1;
$class1->printOut();
echo $class1->getValue() . "\n";
//create object of ConcreteClass2
$class2 = new ConcreteClass2;
$class2->printOut();
echo $class2->getValue() . "\n";
?>