Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix formInterface stub #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2022
Merged

Conversation

VincentLanglet
Copy link
Contributor

Hi @ondrejmirtes,

A formInterface is not \Traversable<int|string, \Symfony\Component\Form\FormInterface> but \Traversable<string, \Symfony\Component\Form\FormInterface>

From https://github.com/symfony/symfony/blob/6.1/src/Symfony/Component/Form/FormInterface.php#L21-L24

@ondrejmirtes ondrejmirtes merged commit 5d2d5ad into phpstan:1.2.x May 27, 2022
@ondrejmirtes
Copy link
Member

Thank you.

@VincentLanglet
Copy link
Contributor Author

@ondrejmirtes, I recently encounter an issue related to this stub change.
You can see symfony/symfony#46698 for more information.

This is a lot related to the fact that array-key like '1' are automatically cast to int by php.
It seems like Symfony often use such name as key.

An exemple, code like

foreach ($form as $name => $child) {
     $form->remove($name);
}

fail with strict types because the $name is sometimes an int and remove expects a string.

So I start to wonder if it's not better to keep

\Traversable<string|int, \Symfony\Component\Form\FormInterface>

in order to prevent people "You might need to cast keys to string".

WDYT if I revert this PR with a comment ?

@VincentLanglet
Copy link
Contributor Author

Will be solved in 6.2 by symfony/symfony#46813

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.

2 participants