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
Release: 2025-01-05 18:54:41
Original
317 people have browsed it

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() {...}
Copy after login

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[]
 */
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template