<?php
class Book {
  private $title;

  public function __get($property) {
    if (!property_exists($this, $property)) {
      throw new Exception('No such property: ' . $property);
    }

    $method = 'get' . ucfirst($property);
    if (!method_exists($this, $method)) {
      throw new Exception('No such method: ' . $method);
    }

    return $this->$method();
  }

  public function __set($property, $value) {
    if (!property_exists($this, $property)) {
      throw new Exception('No such property: ' . $property);
    }

    $method = 'set' . ucfirst($property);
    if (!method_exists($this, $method)) {
      throw new Exception('No such method: ' . $method);
    }

    $this->$method($value);
  }

  public function setTitle($title) {
    $this->title = $title;
  }

  public function getTitle() {
    return $this->title;
  }
}

$book = new Book;
$book->title = 'Code Complete';
print $book->title;
