Comments for documentation PHP post data and returning JSON

1.3k views Asked by At

I have two questions actually:

  1. For some functions I am posting forms to them, can I mention them as @params in comments or what:

    /* some descriptions 
     *
     * @param string userName
     */
    
    
    
    public function add(){ 
               $userName = $_POST['user']
            ......
    }
    
  2. From some function I am returning data as JSON, how to mention JSON as return type and format:

     /* some descriptions 
      *
      * @return JSON [{id, name,...}]
      */
    
1

There are 1 answers

0
avy On BEST ANSWER

You can write anything you like in comments. That said, it's not a conventional use - @param and @return should describe the actual parameters and return values of the function in question. See e.g. the draft PHP-FIG recommendation for what's (mostly) conventional.

If you're returning a JSON string it would be better to document it as

@return string Text here describing what is being returned

since as far as PHP is concerned it's just another string.