Netorica
Netorica

Reputation: 19327

two or more datatypes in PHPdoc @param

ok I do have this phpdoc above of my class method

/**
 * this a function that translates the text
 * @param string|boolean $lang if string the string given in the parameter will be the language code that will represent the language desired, if true, this will translate based on the website's current language, if false will not translate.
 */

now my problem is, is how I can define the datatype of the $lang that can accept both string and boolean ONLY.

In other documentations I saw mixed but its not reflecting correctly in my Eclipse IDE with PDT.

My question is what is the standard way on how i can display that a certain @param is possible to accept two or more kinds of datatype.

NOTE: the phpdoc i have given is an existing documentation of the application I am working at now. Well I'm assigned for documenting everything well.

Upvotes: 23

Views: 13059

Answers (1)

Ian Hunter
Ian Hunter

Reputation: 9774

You've done it right. The PHPDoc reference gives these two options for parameters that can be multiple data types (emphasis mine).

The datatype should be a valid PHP type (int, string, bool, etc), a class name for the type of object, or simply "mixed". Further, you can list multiple datatypes for a single parameter by delimiting them with the pipe (e.g. "@param int|string $p1").

Upvotes: 31

Related Questions