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:
<embed src="flash_game.swf" width="450" height="350" />
#id:first-line { font-weight: bold; color: blue; }
var url = window.location; alert(url);
$homepage = file_get_contents("http://coursesweb.net/"); echo $homepage;