Function list of php file

前端 未结 12 1285
南方客
南方客 2020-11-28 14:40

How to get list of functions that are declared in a php file

12条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 15:03

    I solved this problem with array_diff

    $funcs = get_defined_functions()["user"];
    
    require_once 'myFileWithNewFunctions.php'; // define function testFunc() {} here
    
    var_dump( array_values( array_diff(get_defined_functions()["user"], $funcs) ) )
    // output: array[ 0 => "test_func"]
    

    Update

    To get the "real" functions name try this

    foreach($funcsDiff AS $newFunc) {
       $func = new \ReflectionFunction($newFunc);
       echo $func->getName(); // testFunc
    }
    

提交回复
热议问题