Enforcing Property Access Using Magic Accessor Methods

<?
class Person {    protected $__data = array('person', 'email');    public function __get($property) {
        if (isset($this->__data[$property])) {
            return $this->__data[$property];
        } else {
            return false;
        }
    }    public function __set($property, $value) {
        if (isset($this->__data[$property])) {
            return $this->__data[$property] = $value;
        } else {
            return false;
        }
    }
}
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.