8

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?

1

1 Answer 1

10

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

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! I thought I was looking at "the documentation" :C Didn't realize there was another doc out there with more info.
The link no longer leads to the location expected.
@BorisD.Teoharov I updated the link to use the Internet Archive and added the relevant info into the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.