The abstract classes and methods are used to create a model of minimum required methods which must be defined in normal sub-classes derived from an abstract class (with extends).
An abstract class is created with the abstract keyword.
An abstract class cannot be instantiated, can only be inherited by other sub-classes extended from it.
abstract public function methodName($arguments);Abstract methods are only created in an abstract class.
<?php // AbstractClass class abstract class AbstractClass { protected $name; // declare an abstract method abstract public function greetName($greet); // define a normal method public function setName($name) { $this->name = $name; // sets the value of $name property } } ?>Any attempt to create an object instance of the AbstractClass will cause an error like this:
<?php // ... include AbstractClass code // a child class derived from AbstractClass class ChildClas extends AbstractClass { // the required method public function greetName($greet) { return $greet. ' '. $this->name; } // another method, returns today's date public function todayDate() { return 'Today: '. date('l, j-n-Y'); } } ?>If we were to create a child class derived from AbstractClass that does not implement the greetName() method, will generate an error like this:
<?php // ... include ChildClas code // object instance of ChildClas $obj = new AbstractClass(); // calls setName(), defined in AbstractClass $obj->setName('MarPlo'); // access the methods defined in ChildClas class echo $obj->greetName('Welcome'); echo '<br />'. $obj->todayDate(); ?>Will display:
<img src="image.jpg" usemap="#map1"> <map name="map1"> <area shape="rect" coords="9, 120, 56, 149" href="#"> <area shape="rect" coords="100, 200, 156, 249" href="#"> </map>
#id { overflow: auto; }
document.getElementById("id").onmouseover = function(){ document.write("Have Good Life"); }
if(isset($_GET["id"])) { echo $_GET["id"]; }