Fork me on GitHub
PhpDoc2Cheatsheet

Lot of Code Snippets for phpDocumentor

FILEback to top


/** File docBlock description
*
* This block demonstrates the rich
* information that can be included
* in in-code documentation through
* DocBlocks and tags
* @author Jane Doe 
* @version 1.0
* @package sample
*/

VARIABLEback to top


Elements

/**
* Global variable declaration docBlock
* @global integer $GLOBALS['_myvar']
* @name $_myvar
*/

$GLOBALS['_myvar'] = 6;

CLASSback to top


/**
* An example class, this is grouped with
* other classes in the "sample" package and
* is part of "classes" subpackage
* @package sample
* @subpackage classes
*/

class myclass {
...
}

FUNCTIONback to top


/**
* A sample function docblock
* @global string document the use $_myvar
* @staticvar integer $staticvar is returned
* @param string $param1 name to declare
* @param string $param2 value of the name
* @return integer
*/

function aFunc($param1, $param2='optional') {
  static $staticvar = 7;
  global $_myvar;
  return $staticvar;
}

TAGSback to top


@api

/**
* This method will not change until a major release.
*
* @api
*
* @return void
*/

function showVersion()
{
  <...>
}

@author

/**
* @author My Name
* @author My Name 
*/

@category

/**
* Page-Level DocBlock
*
* @category MyCategory
* @package  MyPackage
*/

@copyright

/**
* @copyright 1997-2005 The PHP Group
*/

@deprecated

/**
* @deprecated
* @deprecated 1.0.0
* @deprecated No longer used by internal code and not recommended.
* @deprecated 1.0.0 No longer used by internal code and not recommended.
*/

function count()
{
  <...>
}

@example

/**
* @example example1.php Counting in action.
* @example http://example.com/example2.phps Counting in action by a 3rd party.
* @example "My Own Example.php" My counting.
*/

function count()
{
  <...>
}

@filesource

/**
* @filesource
*/

@deprecated

/**
* @deprecated
* @deprecated 1.0.0
* @deprecated No longer used by internal code and not recommended.
* @deprecated 1.0.0 No longer used by internal code and not recommended.
*/

function count()
{
  <...>
}

@global

This tag is not included in phpDocumentor 2.0
/**
  *@global [Type] [name] @global [Type] [description]*/

@ignore

if ($ostest) {
  /**
  * This define will either be 'Unix' or 'Windows'
  */
  define("OS","Unix");
} else {
  /**
  * @ignore
  */
  define("OS","Windows");
}

@internal

/**
* @internal
*
* @return integer Indicates the number of items.
*/

function count()
{
  <...>
}

@internal

/**
* @internal
*
* @return integer Indicates the number of items.
*/

function count()
{
  <...>
}

@link

Normal tag:
/**
  * @link http://example.com/my/bar Documentation of Foo.
  *
  * @return integer Indicates the number of items.
  */

 function count()
 {
     <...>
 }
Inline tag:
/**
  * This method counts the occurrences of Foo.
  *
  * When no more Foo ({@link http://example.com/my/bar}) are given this
  * function will add one as there must always be one Foo.
  *
  * @return integer Indicates the number of items.
  */

 function count()
 {
     <...>
 }

@license

/**
* @license GPL
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/

@method

class Parent
{
  public function __call()
  {
    <...>
  }
}

/**
* @method string getString()
* @method void setInteger(integer $integer)
* @method setString(integer $integer)
*/

class Child extends Parent
{
  <...>
}

@package

/**
                * @package PSR\Documentation\API
                */

@param

/**
* Counts the number of items in the provided array.
*
* @param mixed[] $array Array structure to count the elements of.
*
* @return int Returns the number of elements.
*/

function count(array $items)
{
  <...>
}

@property

  class Parent
{
  public function __get()
  {
    <...>
  }
}

/**
* @property string $myProperty
*/

class Child extends Parent
{
  <...>
}

@property-read

class Parent {
     public function __get()
     {
      <...>
     }
 }

 /**
 * @property-read string $myProperty
 */

 class Child extends Parent
 {
  <...>
 }

@property-write

class Parent
     {
     public function __set()
     {
     <...>
   }
 }

 /**
 * @property-write string $myProperty
 */

 class Child extends Parent
 {
 <...>
}

@return (Singular type)

/**
  * @return integer Indicates the number of items.
  */

  function count()
  {
    <...>
}

@return (two types)

/**
  * @return string|null The label's text or null if none provided.
  */

  function getLabel()
  {
    <...>
}

@see

/**
  * @see http://example.com/my/bar Documentation of Foo.
  * @see MyClass::$items           for the property whose items are counted
  * @see MyClass::setItems()       to set the items for this collection.
  *
  * @return integer Indicates the number of items.
  */

  function count()
  {
    <...>
}

@since

/**
  * @since 1.0.1 First time this was introduced.
  *
  * @return integer Indicates the number of items.
  */

  function count()
  {
    <...>
}

/**
* @since 1.0.2 Added the $b argument.
* @since 1.0.1 Added the $a argument.
* @since 1.0.0
*
* @return void
*/

function dump($a, $b)
{
 <...>
}

@source

/**
  * @source 2 1 Check that ensures lazy counting.
  */

  function count()
  {
  if (null === $this->count) {
    <...>
  }
}

@subpackage

/**
  * @package PSR
  * @subpackage Documentation\API
  */

@throws

/**
  * Counts the number of items in the provided array.
  *
  * @param mixed[] $array Array structure to count the elements of.
  *
  * @throws InvalidArgumentException if the provided argument is not of type
  *     'array'.
  *
  * @return int Returns the number of elements.
  */

  function count($items)
  {
    <...>
}

@todo

/**
  * Counts the number of items in the provided array.
  *
  * @todo add an array parameter to count
  *
  * @return int Returns the number of elements.
  */

  function count()
  {
    <...>
}

@uses & @used-by

/**
  * @uses MyClass::$items to retrieve the count from.
  *
  * @return integer Indicates the number of items.
  */

  function count()
  {
    <...>
}

@version

/**
    * @version 1.0.1
    */

    class Counter
    {
      <...>
  }

  /**
  * @version GIT: $Id$ In development. Very unstable.
  */

  class NeoCounter
  {
    <...>
}

ARRAYSback to top


unspecified:

@return array

specified containing a single type:

@return int[]

specified containing multiple types:

@return (int|string)[]

MULTIPLE TYPESback to top


@return int|null