dynamic function name php code example

Example 1: 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);

Example 2: dynamic function name php

$function = $prefix . '_custom_type_init';
if(function_exists($function)) {
  $function();
}

Tags:

Misc Example