| 
<?php
/*
 * This is the demo page.
 * It shows how to dynamically create objects on the fly in
 * different ways.
 * @author Roy
 */
 require_once('./class/Factory.class.php');
 spl_autoload_register(array('Factory', 'autoload'));
 
 //This array is the $title, $price, $category of Movie
 $param1 = array('Little Prince', 100, 'Children');
 
 try{
 
 // ArrayList shows how to use SPL
 $movies = new ArrayList();
 
 // different ways to create Movie object
 $movies->add(Factory::create('Movie', $param1));
 $movies->add(new Movie('Fast and Furious', 25, 'PG 13'));
 
 /*
 * Movie object does not contain any GETTER
 * Those functions are generated on the fly
 */
 foreach($movies as $movie) {
 echo $movie->getTitle().'<br />';
 }
 
 } catch(Exception $e) {
 print_r('<b>Error: </b>'.$e->getMessage());
 }
 
 ?>
 |