创建PHP类大纲
作者:互联网
我正在寻找一个可以有效勾画一个类的函数或类:
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的’);
有没有人知道,或知道一种轻松写这个的方法?
解决方法:
看看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注释,并以开头/ **开头
标签:outline,php,object,architecture,class-design 来源: https://codeday.me/bug/20190827/1737659.html