Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2. class test{
  3. private $functions = array();
  4. private $vars = array();
  5.  
  6. function __set($name,$data)
  7. {
  8.   if(is_callable($data))
  9.     $this->functions[$name] = $data;
  10.   else
  11.    $this->vars[$name] = $data;
  12. }
  13.  
  14. function __get($name)
  15. {
  16.   if(isset($this->vars[$name]))
  17.    return $this->vars[$name];
  18. }
  19.  
  20. function __call($method,$args)
  21. {
  22.   if(isset($this->functions[$method]))
  23.   {
  24.    call_user_func_array($this->functions[$method],$args);
  25.   } else {
  26.    // error out
  27.   }
  28. }
  29. }
  30.  
  31. // LET'S BREAK SOME LAW NOW!
  32. $obj = new test;
  33.  
  34. $obj->sayHelloWithMyName = function($name){
  35. echo "Hello $name!";
  36. };
  37.  
  38. $obj->sayHelloWithMyName('Fabio'); // Hello Fabio!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement