php calling function dynamically code example

Example 1: php dynamic function call

public function view_all($building_post_id, $member_id = array());

//
$this->view_all($building_post_id); 		// CORRECT, no need pass default params
$this->view_all($building_post_id, 12);		// CORRECT, pass default params

Example 2: php call dynamic function

//Simple
$vFn = "Login";
$vFn();

//OR
call_user_func($vFn, $vars); //Returns the return value of the callback.

//Best
abstract class mBase {
	public function main() {
    	.....
  	}
}

class mA extends mBase {
	public function main() {
    	parent->main();
    	.....
  	}
}

class mB extends mBase {
  	public function main() {
    	parent->main();
    	.....
  	}
}
function runMM(mBase $module) {
  $module->main();
}
$m = 'mB'; //example
runMM ($m);

Tags:

Php Example