How can I create a function dynamically?

后端 未结 5 1498
独厮守ぢ
独厮守ぢ 2020-12-31 05:28

I have a variable like $string = \"blah\";

How can I create a function that has the variable value as name? Is this possible in PHP?

Like

5条回答
  •  孤独总比滥情好
    2020-12-31 05:40

    this might not be a good idea, but you can do something like this:

    $string = "blah";
    $args = "args"
    $string = 'function ' . $string . "({$args}) { ... }";
    eval($string);
    

提交回复
热议问题