Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created June 13, 2010 21:06
Show Gist options
  • Save leejarvis/437002 to your computer and use it in GitHub Desktop.
Save leejarvis/437002 to your computer and use it in GitHub Desktop.
<?php
class Person {
var $name;
public function __construct($name) {
$this->name = $name;
}
public function __get($value) {
if ($value == 'username') {
return $this->name;
}
}
public function __set($field, $value) {
if ($field == 'age') {
$this->age = $value;
}
}
public function __call($func, $args) {
echo "What the fuck are you doing?\n";
print_r($args);
}
public function __toString() {
$str = "My name is ".$this->name;
if ( isset($this->age) ) $str .= " and I am ".$this->age." years old";
return $str;
}
}
$peter = new Person("Peter");
echo $peter->username."\n";
$peter->age = 30;
echo $peter;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment