开发者

Create a PHP Class Outline

开发者 https://www.devze.com 2023-02-06 09:01 出处:网络
I am looking for a function or class that can effectively outline a class: class MyClass{ /* * Perhaps include the function comments

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?


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 /**


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

0

精彩评论

暂无评论...
验证码 换一张
取 消