The so-called variable function refers to calling a function through the value of a variable. Because the value of a variable is variable, different functions can be called by changing the value of a variable. It is often used in callback functions, function lists, or to call different functions based on dynamic parameters. The method of calling a variable function is to add parentheses to the variable name.
function name() {
echo 'jobs';
}
$func = 'name';
$func(); //调用可变函数Variable functions can also be used in object method calls.
class book {
function getName() {
return 'bookname';
}
}
$func = 'getName';
$book = new book();
$book->$func();