Does PHP support the declaration of user-defined functions in the form of variables? I tried to use & lt ;? Phpfunction & nbsp; $ a {}$ a & nbsp; test ();? & Gt; an error is prompted. ------ Solution ------------------ you can implement (_ call) through the class ------ solution -------- custom function name
Does PHP support variable-based function names when declaring custom functions?
I tried
Function $ {}
$ A = 'test ';
Test ();
?>
Error message.
------ Solution --------------------
You can implement (_ call) through a class)
------ Solution --------------------
1. use eval
$ A = 'test ';
Eval ("function $ a () {echo 'function name is: '. _ function __;}");
Test ();
2. use the magic method of class _ call
Class foo {
Public function _ call ($ name, $ param ){
If ($ name = 'test '){
Echo 'test ';
} Else {
Echo 'name not exists ';
}
}
}
$ Obj = new foo ();
$ A = 'test ';
$ Obj-> $ ();