Skip to content

Instantly share code, notes, and snippets.

@ilyabrin
Created March 28, 2012 00:46
Show Gist options
  • Save ilyabrin/2222343 to your computer and use it in GitHub Desktop.
Save ilyabrin/2222343 to your computer and use it in GitHub Desktop.
PHP 5.3 :: Magic on the fly
<?php
## PHP :: add new pros an the fly
class magicMethod {
private function magic($name, $value) {
$this->$name = $value;
}
function __set($name, $value) {
$this->magic($name, $value);
}
}
// E X A M P L E //
$foo = new Foo();
print_r($foo); // Foo Object()
$foo->bar = 42;
print_r($foo); // Foo Object( [bar] => 42 )
print_r($foo->bar); // 42
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment