Login   Register  
PHP Classes
elePHPant
Icontem

File: test.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Olavo Alexandrino  >  Access Methods  >  test.php  >  Download  
File: test.php
Role: Example script
Content type: text/plain
Description: An example of use
Class: Access Methods
Map variable accesses to accessor method calls
Author: By
Last change:
Date: 2006-07-19 05:06
Size: 1,612 bytes
 

Contents

Class file image Download
<?php require_once("class.AccessMethods.php"); ?>
<?php
/*
 * The Person Class. This class is used only to test the AccessMethods class.
 * It has some properties that you can test and prove the usability of AccessMethods class for get and set values of properties.
 * Make its class!!
 * @author Olavo Alexandrino <oalexandrino@yahoo.com.br>
 */
class Person
{
    private 
$_name;
    
    private 
$_gender;
    
    private 
$_age 25;
    
    private 
$_foreigner false;
    
    public function 
__construct(  )
    {
    }    

    public function 
isForeigner()
    {
        return 
$this->_foreigner;
    }

    public function 
getAge()
    {
        return 
$this->_age;
    }
    
    public function 
getName()
    {
        return 
$this->_name;
    }
    
    public function 
setName$name )
    {
        
$this->_name $name;
    }    
    
    public function 
getGender()
    {
        return 
$this->_gender;
    }
    
    public function 
setGender$gender )
    {
        
$this->_gender $gender;
    }    
    
    public function 
__get($name)
    {
        return 
AccessMethods::get($name,$this);
    }

    public function 
__set($name,$value)
    {
        
AccessMethods::set($name,$value,$this);
    }        
    
}

$objPerson = new Person();
$objPerson->Name "Olavo";
$objPerson->Gender "Male";

// This line will raise an exception. Uncomment and see!
//$objPerson->Age = "M";

print "This is an example !!!";
print 
"<br/><br/>";
print 
"His name is:   " $objPerson->Name   "<br/>";
print 
"His gender is: " $objPerson->Gender "<br/>";
print 
"He's "$objPerson->Age "<br/>";
print (
"About her nationality: " . (($objPerson->Foreigner) ? "He's foreigner" "He isn't Foreigner") );
?>