In phpdoc comments, is there any way to limit the @var type to a set of allowed values?

StackOverflow https://stackoverflow.com/questions/21170120

  •  28-09-2022
  •  | 
  •  

Question

In my classes, some 'boolean' values are stored as an integer, acceptable values being 1 or 0. So the actual type is not BOOLEAN, but INT. However, only 1 and 0 are acceptable values. In my phpdoc comment block, I would like to display this. How would I show that the only acceptable values are 1 and 0 as int?

Pseudo Example:

/**
 * @var int{0,1} $isAccepted
 */
Était-ce utile?

La solution

You cannot limit ranges in phpDoc. You can only suggest it in the description like so:

/**
 * @var int $isAccepted Boolean, accepts 1 or 0
 */
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top