* */
echo "<p>Create a new Bird Object...</p>";
$hummingbird = new Bird();
/*
try out the various functions
*/
echo "<p>Run sing() function...</p>";
$hummingbird->sing();
echo "<p>Run and echo getSong() function ...</p>";
echo $hummingbird->getSong();
echo "<p>Run setSong() to change the Brid's song...</p>";
$hummingbird->setSong("Caw caw!");
echo "<p>Run and echo the song to prove it has been changed...</p>";
echo $hummingbird->getSong();
echo "<p>Run demonstrateBirdness()...</p>";
$hummingbird->demonstrateBirdness();
echo "<p>Create another new Bird Object...</p>";
$eagle = new Bird();
$eagle->setSong("Screech!");
$eagle->demonstrateBirdness();
?>
	</span>
	<h3>Comparing Objects</h3>
   <p>The <strong>==</strong> comparison operator determines if two objects are different instances of the same class, and whose properties share the same values. The <strong>===</strong> comparison returns true only if the two objects being compared are instances of the same class. Use <a href="http://php.net/manual/en/function.get-class.php">get_class( )</a> to determine what class an object is.</p>	
   <span>
	<?php 
echo "<hr /><p>Compare similar Bird objects with different state...</p>";
if ($eagle == $hummingbird) {
    echo "<p>The \$eagle is == to \$hummingbird</p>";
} else {
    echo "<p>The \$eagle is NOT == to \$hummingbird</p>";
$objectAsSerializedString = serialize($obj);

//...store $objectAsSerializedString in a DB or text file
//later, when its time to retrieve (re-instantiate) the object...

$newObj = unserialize( $objectAsSerializedString );
echo $newObj->data;
</code></pre>	
<span>
    <?php 
function __autoload($classname)
{
    require_once "./" . $classname . ".php";
}
$myBird = new Bird("Yellow", "Tweet");
$myBird->demonstrateBirdness();
echo "<h3>Serializing an Object into a string...</h3>";
$serializedString = serialize($myBird);
echo "<h3>Display the serialized string...</h3>";
echo "<p>" . $serializedString . "</p>";
/*
at this point, we could store the string in a cookie or database...

...later, when we need to retrieve the Object,  
use the string to re-instantiate the object with all the same property values
*/
echo "<h3>Unserializing an Object...</h3>";
$aReinstantiatedBird = unserialize($serializedString);
echo "<h3>Demonstrate the re-instantiated Object...</h3>";
$aReinstantiatedBird->demonstrateBirdness();
?>
	<h1>Class Design: Constructors</h1>
   <p>A constructor is a special function within a class definition, that is automatically invoked as soon as an object is instatiated. It provides a chance for the class designer to ensure properties are appropriately initialized.</p> 
   <p>PHP is unlike some other OOP languages, in that the constructor function does not share the name of the class, but is given the function name <strong><a href="http://php.net/manual/en/language.oop5.decon.php">__construct( )</a></strong> NOTE the double underscore preface.</p>
   <p>Officially,the constructor is one of many so-called 'magic functions' in PHP. Magic functions are reserved function names and have special behaviors, such as never being explicitly invoked by the developer (PHP invokes them automatically). All magic function names are prefaced with two underscores.</p> 
<pre><code>
class MyClass{
	public function __construct(){
		//this function is invoked automaticcalky
		//during Object instantiation
	}
}
</code></pre>
<span>
    <?php 
/*
load the Bird.php file
examine the source code and locate the constructor
determine if parameters will be required at instantiation
*/
require_once "Bird.php";
/*
pass parameter arguments to the constructor at instantiation
*/
$whiskeyJack = new Bird("Blue", "Tweet!");
$hawk = new Bird("Black", "Screech!");
$whiskeyJack->demonstrateBirdness();
?>
</span>

</body>
</html>
loading the appropriate class file
*/
function __autoload($classFileName){
	require_once("path/to/classfiles/" . $classFileName  . ".php");
}

$obj1 = new MyClass01();	//__autoload() will load MyClass01.php
$obj2 = new MyClass02();  //__autoload() will load MyClass02.php
</code></pre>	
<span>
    <?php 
/*
autoload any/all classes needed by this page
if present, this function is automaticaly invoked by PHP
*/
function __autoload($classFileName)
{
    /*
    whenever code in this page needs a Class definition, 
    __autoload() will be invoked
    the $parameter will be the string name of the class needed
    */
    require_once $classFileName . ".php";
}
//instantiate a Bird, use it's functions
$budgie = new Bird("Black", "La la la");
$budgie->demonstrateBirdness();
?>
</span>
</body>
</html>