如何从.php文件中获取函数名称? 需要一个PHP脚本

如何从.php文件中获取函数名称? 需要一个PHP脚本

问题描述:

Suppose there is a input file. The file contains php class with many functions and public variable.

I need a php script that would take that input file and count how many php function are there. This script will also print the function name like ..

public function hasMethod($method)
public function isVirtualField($field)

Can anyone post such php script to do this ?

假设有一个输入文件。 该文件包含具有许多函数和公共变量的php类。 p>

我需要一个PHP脚本来获取该输入文件并计算有多少php函数。 此脚本还将打印 函数名称如.. p>

 公共函数hasMethod($ method)
公共函数isVirtualField($ field)
  code>  pre> 
 
 

任何人都可以发布这样的PHP脚本吗? p> div>

get_class_methods() will give you all methods in a given object or class name, see PHP func ref

require_once('Model.php');
$methods = get_class_methods('Model');
print_r($methods);

Will show you all methods of the class Model in file Model.php

class theclass {
    // constructor
    function theclass() {
        return;
    }

    function func1() {
        return;
    }

    // method 2
    function func2() {
        return;
    }
}

    $class_methods = get_class_methods('theclass');

foreach ($classFunctions as $functionName) {
    echo "$functionName
";
}