Overriding parent methods : Inheritance « Class « PHP






Overriding parent methods

 
class DB {
 public $result;

 function getResult() {
  return $this->result;
 }

 function query($sql) {
  error_log("query() must be overridden by a database-specific child");
  return false;
 }
}

class MySQL extends DB {
 function query($sql) {
  $this->result = mysql_query($sql);
 }
}
  
  








Related examples in the same category

1.subclass and parent class
2.Three levels of inheritance
3.extends and implement
4.Basic Inheritance
5.Class Inheritance
6.Class Member Binding in PHP
7.Creating a Class That Inherits from Another
8.Define an Executive class that inherits Employee
9.inheritance example
10.Using the extends keyword to define a subclass
11.Example of Inheritance
12.Using inheritance to efficiently represent various vehicle types
13.Using the parent construct