php convert string to method call

后端 未结 3 1613
臣服心动
臣服心动 2021-01-15 08:25


        
3条回答
  •  深忆病人
    2021-01-15 08:47

    This feature is known as Variable functions, here is an example from php.net:

     \n";
     }
    
     function bar($arg = '')
     {
         echo "In bar(); argument was '$arg'.
    \n"; } // This is a wrapper function around echo function echoit($string) { echo $string; } $func = 'foo'; $func(); // This calls foo() $func = 'bar'; $func('test'); // This calls bar() $func = 'echoit'; $func('test'); // This calls echoit() ?>

    More Info:

    • http://php.net/manual/en/functions.variable-functions.php

提交回复
热议问题