Description of PHP functions efficiently

How can you describe the parameters and return type (getter / setter) of your PHP functions?

I need to tell the moderator the return type and specify the parameters for each function. I have hundreds of functions, so this becomes a problem, since I need to do this for each individual revision.

I am currently using the following procedure

  • ack-grep "function " > /tmp/functions 2. In Wim:
    • %s/\d//g, %s/{//, %s/://g
    • `% s /.* PHP / \ U &. /
    • then placing the Uppercase file name at the top of the list of functions of each file
    • put functions in one file and parameters in another file so that matching lines
    • create a third file in which you write setteror getterfor the corresponding line
  • paste -d"&" /tmp/{functions,functions_param,functions_type}
  • add LaTeX formatting to each feature set of each file
+3
source share
2 answers

Use something like phpdoc .

Basically you add special comments to your code:

/**
 * A sample function docblock
 * @global string document the fact that this function uses $_myvar
 * @staticvar integer $staticvar this is actually what is returned
 * @param string $param1 name to declare
 * @param string $param2 value of the name
 * @return integer 
 */
function firstFunc($param1, $param2 = 'optional') {
    static $staticvar = 7;
    global $_myvar;

    return $staticvar;
}

and it automatically creates HTML documentation for it.

Basically, the idea is to make life easier for the programmer and let you write documentation using the API without having to spend a lot of time on it.

There are several IDEs that also understand this and will show the documentation while you use it. For example, the function:

/** Retrieve the action key
 * @return string
 */
function isValid($value) {
  ....
}

Shows it in the Zend studio: http://static.zend.com/topics/code-assist.png

, IDE, ( , Zend, ), , , , , , , , .

+8

PHPDoc. sum, :

/**
 * Adds up two int numbers
 * @param int $x the first number to add
 * @param int $y the second number to add
 * @return int the result of the operation
 */
 function my_sum ($x, $y)
 {
     return $x+$y;
 }
+4

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


All Articles