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:
<ul> <li>http://coursesweb.net/html/</li> <li>http://coursesweb.net/css/</li> </ul>
.some_class { display: list-item; }
var obj = { "courses": ["php", "javascript", "ajax"] }; var jsonstr = JSON.stringify(obj); alert(jsonstr); // {"courses":["php","javascript","ajax"]}
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>'; $dochtml = new DOMDocument(); $dochtml->loadHTML($strhtml); $elm = $dochtml->getElementById("dv1"); echo $elm->nodeValue; // CoursesWeb.net