3

我正在寻找一个可以有效地勾勒出一个类的函数或类:

class MyClass{

  /*
  * Perhaps include the function comments
  * in the function.
  */
  function mainFunction(){
    //Does Something
  } 

  function functionWithArgs($arg1,$arg2=false){
    //Does Something
    //The function I want will give e the arguments w/default values
  }

}

是否存在一个函数或库可以让我访问有关此类的信息,甚至是文件。

前任。

get_file_outline('fileWithAboveClass.php');

或者

get_class_outline('MyClass');

有没有人知道,或者知道一种轻松写这个的方法?

4

2 回答 2

6

看看 PHP反射 API

//use the ReflectionClass to find out about MyClass
$classInfo = new ReflectionClass('MyClass'); 

//then you can find out pretty much anything you want to know...
$methods = $classInfo->getMethods(); 
var_dump($methods);

//you can even extract your comments, e.g.
$comment=$classInfo->getMethod('mainFunction')->getDocComment();

请注意,要使评论提取起作用,它们必须像 PHPDoc / Doxygen 评论一样格式化,并以开头/**

于 2011-01-22T19:31:22.407 回答
0

还有一个命令行选项可用于检查函数和类。

$ php --rc DateTime

将为您提供有关 DateTime 类的所有详细信息,同时

$ php --rf in_array

将为您提供“in_array”函数的参数。

如果您在编码时使用终端,它可以非常方便地使用,而不是一直在 PHP 手册中查找;)

于 2011-01-22T21:30:19.853 回答