Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are valid values for PHPDoc's @param annotation?

Tags:

php

phpdoc

I'm on PHPdocs Reading this :

The datatype should be a valid PHP type (int, string, bool, etc)," which is fine, but they don't say which strings (such as int, string, bool) to use to identify the other types.

I'm GUESSING they use the (cast) syntax to determine the type to be used for the annotations, but something like floating point in PHP doesn't have a cast operator for it so I'm not sure what to use for that. Maybe it's float, or maybe it's fp.

Does anyone have a definitive list of the basic types in PHP and what string should be used to identify them in your PHPdocs?

like image 528
Jazzepi Avatar asked Apr 14 '13 11:04

Jazzepi


People also ask

What does @param mean in PHP?

The @param tag is used to document a single argument of a function or method.

What are PHP annotations?

Introduction. Annotation is a form of syntactic metadata that can be added to source code. Annotations can be embedded in and read using reflection mechanism. Annotations are known from Java or so-called Attributes in C# and can be retained by VM at run-time and read via reflection.


1 Answers

It's all listed in the documentation: http://phpdoc.org/docs/latest/references/phpdoc/types.html (original link is dead; now links to Internet Archive copy)

For floats, the keyword is (logically enough) float.


The following keywords are recognized:

string, the element to which this type applies is a string of binary characters.

integer or int, the element to which this type applies is a whole number or integer.

boolean or bool, the element to which this type applies only has state true or false.

float or double, the element to which this type applies is a continuous, or real, number.

object, the element to which this type applies is the instance of an undetermined class.

mixed, the element to which this type applies can be of any type as specified here. It is not known on compile time which type will be used.

array, the element to which this type applies is an array of values, see the section on Arrays for more details.

resource, the element to which this type applies is a resource per the definition of PHP at http://www.php.net/manual/en/language.types.resource.php.

void, this type is commonly only used when defining the return type of a method or function. The basic definition is that the element indicated with this type does not contain a value and the user should not rely on any retrieved value.

null, the element to which this type applies is a NULL value or, in technical terms, does not exist.

A big difference compared to void is that this type is used in any situation where the described element may at any given time contain an explicit NULL value.

callable, the element to which this type applies is a pointer to a function call. This may be any type of callback as defined in the PHP manual at http://php.net/manual/en/language.pseudo-types.php(dead link).

false or true, the element to which this type applies will have the value true or false. No other value will be returned from this element.

This type is commonly used in conjunction with another type to indicate that it is possible that true or false may be returned instead of an instance of the other type.

self, the element to which this type applies is of the same Class, or any of its children, as which the documented element is originally contained.

phpDoc via Internet Archive

like image 108
Dave Avatar answered Oct 25 '22 14:10

Dave