Creating a PHP class structure

I am looking for a function or class that can effectively describe 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 any function or library that can give me some access to information about this class or even a file.

ex.

get_file_outline('fileWithAboveClass.php');

or

get_class_outline('MyClass');

Does anyone know about this or know a way to easily write this?

+3
source share
2 answers

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

Please note that in order to retrieve comments for work, they must be formatted as PHPDoc / Doxygen comments and begin by opening /**

+6
source

A command line option is also available to test functions and classes.

$ php --rc DateTime

will give you all the information about the DateTime class, and

$ php --rf in_array

"in_array".

, , PHP- ;)

0

Source: https://habr.com/ru/post/1787184/


All Articles