PHP Classes

File: demo.php

Recommend this page to a friend!
  Classes of Roy Yu   Object dynamic generation   demo.php   Download  
File: demo.php
Role: Example script
Content type: text/plain
Description: Entry points of this demo, show how to use the classes
Class: Object dynamic generation
Create model classes dynamically
Author: By
Last change: -- change includes path
Date: 16 years ago
Size: 844 bytes
 

Contents

Class file image Download
<?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());
}

?>