Home >Backend Development >PHP Tutorial >How Do I Specify an Array of Objects in PHPdoc Type Hinting?
Specifying Array of Objects in PHPDoc Type Hinting
In PHPDoc, type hinting can be used to indicate the expected type of a variable or function parameter. This enables IDEs like PHPEd to provide code insight based on the type information. However, how do you specify an array of objects in such type hints?
Solution for PHPStorm IDE
For PHPStorm, you can use the syntax /**@var SomeObj[]*/ to indicate an array of SomeObj objects. For example:
/** * @return SomeObj[] */ function getSomeObjects() {...}
PHPDoc Documentation Method
The PHPDoc documentation recommends using a Type definition to specify the type of each array element. Only one Type is expected for a given array. For instance:
/** * @return int[] */
The above is the detailed content of How Do I Specify an Array of Objects in PHPdoc Type Hinting?. For more information, please follow other related articles on the PHP Chinese website!