Pages

Jun 16, 2011

PHP5 Dynamically calling Classes and Methods

Easy peasy:

$class_name = 'NiceClass';
$method_name = 'niceMethod';
$arguments = array('a' => true, 'b' => 5);

if (class_exists($class_name)) {
  $class = new $class_name();
  if (method_exists($class, $method_name)) {  
    $class->$method_name($arguments);
  }
  
}

No comments:

Post a Comment