Home >Backend Development >PHP Tutorial >How Do I Specify an Array of Objects in PHPdoc Type Hinting?

How Do I Specify an Array of Objects in PHPdoc Type Hinting?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-05 18:54:41298browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn