Created
June 13, 2010 21:06
-
-
Save leejarvis/437002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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