Location: PHPKode > scripts > Access Methods > access-methods/test.php
<?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 <hide@address.com>
 */
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") );
?>
Return current item: Access Methods