php - How to define function name using variable? -



how define function name (in php) using variable, this?

$a='blabla'; function {$a}() {.......} 

or that?

the way know give fixed name function use eval, not suggest.

more likely, want stuff function in variable, , call that.

try this:

$a = function() {    echo 'this called anonymous function.';  } $a(); 

edit: if want accessible other files, use global variable:

$globals['variable_name'] = 'my_func_123'; ${$globals['variable_name']} = function() {    echo 'this called anonymous function.';  };  // executing my_func_123() ${$globals['variable_name']}();  

see also: http://php.net/manual/en/functions.anonymous.php


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -