Created
March 28, 2012 00:46
-
-
Save ilyabrin/2222343 to your computer and use it in GitHub Desktop.
PHP 5.3 :: Magic on the fly
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 | |
## 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