Skip to content

[TypeDeclarationDocblocks] Return empty "[]" as "mixed[]" instead of "array{}" on bare "@return array" - #8432

Merged
TomasVotruba merged 1 commit into
mainfrom
return-empty-array-mixed-docblock
Sep 2, 2026
Merged

[TypeDeclarationDocblocks] Return empty "[]" as "mixed[]" instead of "array{}" on bare "@return array"#8432
TomasVotruba merged 1 commit into
mainfrom
return-empty-array-mixed-docblock

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

When a method has a bare @return array docblock and its sole body statement is return [];, DocblockReturnArrayFromDirectArrayInstanceRector previously rewrote it to @return array{}.

array{} describes an always-empty array shape, which is rarely the intent for a method that just happens to return [] in one branch. This turns that case into the looser, more useful mixed[]:

 /**
- * @return array
+ * @return mixed[]
  */
 public function getRefreshTokenKeys()
 {
     return [];
 }

Scope kept narrow on purpose:

  • only fires on a bare @return array tag (not @return mixed, iterable, or an existing generic),
  • only for a direct empty return [],
  • @return mixed[] and typed X[] empties keep being skipped, and no-docblock empties keep generalizing as before.

https://claude.ai/code/session_011MyFdoaYnfDEvdM9o3kiyq

@TomasVotruba
TomasVotruba merged commit 8bbbf1b into main Sep 2, 2026
44 checks passed
@TomasVotruba
TomasVotruba deleted the return-empty-array-mixed-docblock branch September 2, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant