PHP and autoloading · Question 10 of 12

A method returns an array of Conference objects with consecutive keys. Which annotation describes this most precisely for PHPStan?

1 answer is correct. Medium

Show answer

Answer

  • D /** @return list<Conference> */ in addition to the native return type array

Explanation

PHP itself only knows array as a type, and a DocBlock describes the content. list<T> stands for an array with keys 0, 1, 2, …, array<int, T> or array<string, T> for other keys, and Conference[] is the older, less precise short form. PHPStan uses it to check callers and implementation. Conference[] is not valid PHP as a native type.

Certifications & exams

Which exam comes next?

You can already practise for 19 exams, and 21 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications