Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class test{
- private $functions = array();
- private $vars = array();
- function __set($name,$data)
- {
- if(is_callable($data))
- $this->functions[$name] = $data;
- else
- $this->vars[$name] = $data;
- }
- function __get($name)
- {
- if(isset($this->vars[$name]))
- return $this->vars[$name];
- }
- function __call($method,$args)
- {
- if(isset($this->functions[$method]))
- {
- call_user_func_array($this->functions[$method],$args);
- } else {
- // error out
- }
- }
- }
- // LET'S BREAK SOME LAW NOW!
- $obj = new test;
- $obj->sayHelloWithMyName = function($name){
- echo "Hello $name!";
- };
- $obj->sayHelloWithMyName('Fabio'); // Hello Fabio!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement