<?php//****** uses the keyword abstract to declare that the class is an abstraction class ***** abstract class person{ protected $name; protected $age; function __construct ($name = "", $age =18) { $this->name= $name; $this->age= $age; } //*** declares abstract methods in abstract classes **** //*** abstract methods do not have to declare specific behavior *** abstract function getname (); abstract Function getage (); function greeting () { echo "Hello,world"; } } //*** Abstract classes cannot be instantiated directly, but can only be inherited by subclasses *** class newperson1 extends person{ The //*** subclass must implement all the abstract methods in the abstract class *** function getname () { echo "the name is ". $this Name. " <br/> "; } function getage () { echo "the age is ". $this->age. " <br/> "; } } $tom = new newperson1 ("Tom"), $tom->getname (); $tom->getage (); $tom Greeting ();? >
A simple code example of an abstract class of PHP