Skip to content

Default FormType data to mixed#499

Open
alexander-schranz wants to merge 1 commit into
phpstan:2.0.xfrom
alexander-schranz:enhancement/default-mixed-form-type-data
Open

Default FormType data to mixed#499
alexander-schranz wants to merge 1 commit into
phpstan:2.0.xfrom
alexander-schranz:enhancement/default-mixed-form-type-data

Conversation

@alexander-schranz

@alexander-schranz alexander-schranz commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

The same form type can be used with an object or if no data is set unstructured array array<string, mixed> or a none compound simple type string, bool, ...

So the best default to not annoy here is set TData to mixed, still all existing can say they only accept specific data.

In most cases form types not accessing data in them so this mostly unused generic type. Only a few form types accessing data directly.

@VincentLanglet VincentLanglet requested a review from staabm June 9, 2026 11:44

@staabm staabm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not much experience with these types.

feel free to merge if you guys know what you are doing :)

@VincentLanglet

Copy link
Copy Markdown
Contributor

I have not much experience with these types.

feel free to merge if you guys know what you are doing :)

I think the goal here is to add a default in order to avoid forcing the user to type every existing generic Form ; especially because those generic are partially wrong (see #430)

@alexander-schranz

alexander-schranz commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Yes mixed is here better as making wrong assumption during the extension forcing a generic type here. Didn't see #430 before but I agree here that the Form Component is to complex and the phpstan extension forces wrong assumption for generic types now.

So better set a default to mixed and not force them.
Still a form type which set a specific data_class and empty_data and validates it to be only that kind of type can override the generic type still built of top of them.

But default to mixed make it easier, specially you not require accessing the data in lot of custom types. I even would consider it be bad practice outside of listener but thats only my personal opinion :). As mention there also be can data transformers which form component allow via Extension manipulate every type.

@staabm staabm requested a review from ondrejmirtes June 9, 2026 16:43
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.

3 participants