phpDocumentor
[ class tree: phpDocumentor ] [ index: phpDocumentor ] [ all elements ]
Prev Next

@return

Specify the return type of a function or method

by Gregory Beaver
Tag Documentation written by cellog@php.net
Copyright 2002, Gregory Beaver
(phpDocumentor 0.1+)
@return datatype description
@return datatype1|datatype2 description

Description

The @return tag is used to document the return value of functions or methods. @returns is an alias for @return to support tag formats of other automatic documentors

The datatype should be a valid PHP type (int, string, bool, etc), a class name for the type of object returned, or simply "mixed". If you want to explicitly show multiple possible return types, list them pipe-delimited without spaces (e.g. "@return int|string"). If a class name is used as the datatype in the @return tag, phpDocumentor will automatically create a link to that class's documentation. In addition, if a function returns multiple possible values, separate them using the | character, and phpDocumentor will parse out any class names in the return value. phpDocumentor will display the optional description unmodified.

Example

Here's an example:

  1. /**
  2.  * example of basic @return usage
  3.  * @return mixed 
  4.  */
  5. function function1($baz)
  6. {
  7.    if ($baz)
  8.    {
  9.       $a = 5;
  10.    else
  11.    {
  12.       $a = array(1,4);
  13.    }
  14.    return $a;
  15. }
  16.  
  17. /**
  18.  * example of showing multiple possible return types
  19.  * @return int|string could be an int, could be a string
  20.  */
  21. function function2($foo)
  22. {
  23.    if ($foo)
  24.    {
  25.       return 0;
  26.    }
  27.    else
  28.    {
  29.       return "zero";
  30.    }
  31. }
  32.  
  33. class class1
  34. {
  35.    /**
  36.     * example of documenting a method, and using optional description with @return
  37.     * @return string de-html_entitied string (no entities at all)
  38.     */
  39.    function bar($foo)
  40.    {
  41.       return strtr($foo,array_flip(get_html_translation_table(HTML_ENTITIES)));
  42.    }
  43.    
  44.    /**
  45.     * example of using @return with a class name
  46.     * @param integer even or odd integer
  47.     * @return Parser|false phpDocumentor Parser object or error
  48.     */
  49.    function &factory($number)
  50.    {
  51.       $returnval = true;
  52.       if ($number % 2)
  53.       {
  54.           $returnval = new Parser;
  55.       else
  56.       {
  57.           $returnval = false;
  58.       }
  59.       return $returnval;
  60.    }
  61. }

Prev Up Next
@property phpDocumentor tags @see

Documentation generated on Mon, 11 Mar 2019 15:50:06 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.