创建 PHP 类大纲

发布于 2024-10-13 18:16:42 字数 560 浏览 4 评论 0原文

我正在寻找一个可以有效地概述类的函数或类:

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');

有人知道其中之一,或者知道一种轻松编写此代码的方法吗?

I am looking for a function or class that can effectively outline a class:

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
  }

}

Is there a function or library in existence that can give me some kind of access to the information about this class, or even the file.

ex.

get_file_outline('fileWithAboveClass.php');

or

get_class_outline('MyClass');

Does anybody know of either, or know a way of easily writing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

超可爱的懒熊 2024-10-20 18:16:42

看一下 PHP Reflection 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 注释一样,并以开头 /** 开头

Take a look at the PHP Reflection 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();

Note that for the comment extraction to work, they have to be formatted like PHPDoc / Doxygen comments, and begin with an opening /**

九厘米的零° 2024-10-20 18:16:42

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

$ php --rc DateTime

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

$ php --rf in_array

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

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

There's also a command line option available for inspecting functions and classes.

$ php --rc DateTime

will give you all the details about the DateTime-class, while

$ php --rf in_array

will give you the arguments of the "in_array" function.

If you're using the Terminal when coding it can be quite handy to use instead of looking it up in the PHP Manual all the time ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文