Function level annotations help IDEs identify return values or potentially dangerous code
/**
* Adds two numbers together.
*
* @param Int $a First parameter to add
* @param Int $b Second parameter to add
* @return Int
*/
function sum($a, $b)
{
return (int) $a + $b;
}
/**
* ...
File level metadata applies to all the code within the file and should be placed at the top of the file:
<?php
/**
* @author John Doe ([email protected])
* @copyright MIT
*/
If a class extends another class and would use the same metadata, providing it @inheritDoc is a simple way for use the same documentation. If multiple classes inherit from a base, only the base would need to be changed for the children to be affected.
abstract class FooBase
{
/**
* @par...
The @var keyword can be used to describe the type and usage of:
a class property
a local or global variable
a class or global constant
class Example {
/** @var string This is something that stays the same */
const UNCHANGING = "Untouchable";
/** @var string $some_s...
PSR-5 proposes a form of Generics-style notation for collections.
Generics Syntax
Type[]
Type<Type>
Type<Type[, Type]...>
Type<Type[|Type]...>
Values in a Collection MAY even be another array and even another Collection.
Type<Type<Type>>
Type<Type<Type[,...