Snehanshu Snehanshu - 5 months ago 10
PHP Question

PHP - Calling methods whose names are stored in variables

Consider the class

abc


class abc{
public function xyz(){
/*Some processing here*/
return true;
}
};


Suppose I don't know the name of the method directly, but have its name stored in variable, then how can I call the method?

Answer
<?php
class abc{
  public function xyz(){
     /*Some processing here*/
     return true;
  }
};

$method='xyz';  // Define your method name from database
$a= new abc();
$a->$method(); // call method
?>

Would you please refer above code ?