<?php
class Student {
protected $_name;
protected $_email;
public function __call($name, $arguments) {
$action = substr($name, 0, 3);
switch ($action) {
case 'get':
$property = '_' . strtolower(substr($name, 3));
if(property_exists($this,$property)){
return $this->{$property};
}else{
echo "Undefined Property";
}
break;
case 'set':
$property = '_' . strtolower(substr($name, 3));
if(property_exists($this,$property)){
$this->{$property} = $arguments[0];
}else{
echo "Undefined Property";
}
break;
default :
return FALSE;
}
}
}
$s = new Student();
$s->setName('Nanhe Kumar');
$s->setEmail('[email protected]');
echo $s->getName(); //Nanhe Kumar
echo $s->getEmail(); // [email protected]
$s->setAge(10); //Undefined Property
?>