View Single Post
Old 09-12-2010, 10:51 AM  
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
Here we go !
Thanks everyone for your help !

Code:
class foo{
  public $msg;

  public function __call($method, $args){ 
   if(isset($this->$method)){
      $func = $this->$method;
      call_user_func_array($func, $args);
    }
  }

  public function create(){
$method = 'bar';
$this->msg = 'hello';
$parameters = '$param1, $param2';
$param1 = 'William';
$param2 = 'Phorrend';
$code = 'print ($obj->msg." $param1 $param2");';
    $obj = $this;
    $fctStr = "return function($parameters) use(\$obj) { $code };";
    
    $this->$method = eval($fctStr);
    $this->$method($param1, $param2);
  }
}

$foo = new foo();
$foo->create();
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote