<html>
<! GetAndSet.php                                              >
<! Chapter 8, Oracle Database XE PHP Web Programming          >
<! by Michael McLaughlin                                      >
<!                                                            >
<! This script demonstrates how to implement the __get() and  >
<! __set() functions in user-defined classes.                 >
<head>
<title>
  Chapter 8 : GetAndSet.php
</title>
</head>
<body>
<?php
  // Declare a variable to hold an object instance.
  $myObject = new BasicObject();

  // Print an instance variable.
  print "[__get()] [".$myObject->__get("instanceName")."]<br>";

  // Print the __set() call.
  print "[__set()] [\"instanceName\",\"New\")]<br>";

  // Reset the name instance variable,
  $myObject->__set("instanceName","New");

  // Print an instance variable.
  print "[__get()] [".$myObject->__get("instanceName")."]<br>";

  // Define a class that prints a message.
  class BasicObject
  {
    // Declare public instance variable.
    public $instanceName = "Old";

    // Define overloaded getter.
    public function __get($var)
    {
      return $this->$var;
    }

    // Define overloaded setter.
    public function __set($key,$value)
    {
      $this->$key = $value;
    }
  }
?>
</body>
</html>
