Skip to content

Form: getHttpData() return type reflects the $htmlName argument#353

Closed
jaroslavlibal wants to merge 3 commits into
nette:v3.2from
jaroslavlibal:getHttpData-return-type
Closed

Form: getHttpData() return type reflects the $htmlName argument#353
jaroslavlibal wants to merge 3 commits into
nette:v3.2from
jaroslavlibal:getHttpData-return-type

Conversation

@jaroslavlibal

Copy link
Copy Markdown
Contributor

The @return of Form::getHttpData() is not correct.

It says string|string[]|Nette\Http\FileUpload|null, but this only describes the call with a control name. There are two problems:

  1. When called without arguments, the method returns all form data. This is a nested array (the whole POST tree), not string[]. So PHPStan thinks the result is string[] and reports errors on nested access like $data['x']['y'].

  2. For one control, string[] is also not enough. A multi-file upload returns FileUpload[], not only string[].

This PR changes only the docblock to a conditional return type based on $htmlName:

@return ($htmlName is null ? mixed[] : string|string[]|Nette\Http\FileUpload|Nette\Http\FileUpload[]|null)

This probably replaces the older #333.

@jaroslavlibal jaroslavlibal changed the base branch from master to v3.3 June 25, 2026 10:04
@jaroslavlibal jaroslavlibal changed the base branch from v3.3 to v3.2 June 25, 2026 10:04
@dg

dg commented Jun 29, 2026

Copy link
Copy Markdown
Member

Thanks, merged

@dg dg force-pushed the v3.2 branch 2 times, most recently from 4fd678c to 0c7ada6 Compare June 29, 2026 18:54
@dg dg closed this Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getHttpData() PHPDoc typing values as string[], but the actual data can contain nested arrays

2 participants