<html>
<! Inheritance1.php                                           >
<! Chapter 8, Oracle Database XE PHP Web Programming          >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This script declares and instantiate a class, and then     >
<! a subclass that extends the base class. The subclass       >
<! overrides the parent class __construct() function.         >
<head>
<title>
  Chapter 8 : Inheritance1.php
</title>
</head>
<body>
<?php
  // Declare a variable to hold an superclass object instance.
  $myObject1 = new BasicObject("Class");

  // Declare a variable to hold an subclass object instance.
  $myObject2 = new DerivedObject("Subclass");

  // Define a class.
  class BasicObject
  {
    // Declare instance variable.
    protected $instanceName = "";

    function __construct($instanceName)
    {
      // Message on entrance.
      print "[Constructing Instance [".__CLASS__."][".$instanceName."]<br>";

      // Assign parameter to instance variable.
      if (isset($instanceName))
        $this->instanceName = $instanceName;
    }

    protected function getInstanceName()
    {
      return "[".__CLASS__."][".$this->instanceName."]<br>";
    }
  }

  // Define a subclass.
  class DerivedObject extends BasicObject
  {
    // Declare instance variable.
    protected $instanceName = "";

    function __construct($instanceName)
    {
      // Message on entrance.
      print "[Constructing Instance [".__CLASS__."][".$instanceName."]<br>";

      // Assign parameter to instance variable.
      if (isset($instanceName))
        $this->instanceName = $instanceName;

      // Call parent method as self.
      print self::getInstanceName();
    }
  }
?>
</body>
</html>
