Abstact classes use the abstract keyword. It would start as shown below.
abstract class Myabstract{
You cannot instantiate an abstract class. Thus ‘$myclass = new Myabstract;’ does not work. Abstract classes use abstract methods.
Abstract classes are used when you want to make sure that each new child class uses its own method; even though the method exists in the parent class.
Abstract Method
An abstract method would be written like any other method except it contains ‘abstract’ at the beginning. When an abstract method is declared in the parent class, the child classes must their own function under the same name as declared in the parent class.
Example:
abstract function get_var();
}
class childa extends Myabstract{
function get_var() {
echo “Hello World”;
}
}
$mychilda = new childa;
$mychilda->get_var();
© 2018 ALL Rights Reserved | Sitemap
Vancouver | North Vancouver | Burnaby | Richmond | Coquitlam | Port Coquitlam | Surrey | Langley | Maple Ridge | Mission | Abbotsford | Kamloops | Kelowna | Victoria | Squamish | Whistler | Pemberton