Hi,
I'm pretty new to PHP5 OOP and was wondering if someone could advise me on what it the best practice when it comes to using Interceptors.
I have the following simple class, which gets/sets age & name. Is it best to use interceptors? Does anyone use them? I understand that phpDoc has problems documenting them as does intellisense in zendStudio.
Am I best exposing the getAge & setAge classes as public as well as using interceptors?
Thanks
Dave
<?
Class Person {
private $_name;
private $_age;
function __get($property) {
$method = "get{$property}";
if (method_exists($this, $method)) {
return $this->$method();
}
}
function __set($property, $value) {
$method = "set{$property}";
if (method_exists($this, $method)) {
return $this->$method($value);
}
}
private function getName() {
return $this->_name;
}
private function setName($name) {
$this->_name = $name;
}
public function getAge() {
return $this->_age;
}
public function setAge($age) {
$this->_age = strtoupper($age);
}
}
$p = new Person();
$p->Name = "DaveUK";
$p->age = "25";
$p->setAge(($p->getAge() + 10)); // age = 35
$p->age += 10; // using interceptor // age = 45
print "age:". $p->age;
?>