Skip to content
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

Type error caused by FormBuilderIterator #7984

Closed
dmaicher opened this issue Dec 8, 2022 · 2 comments · Fixed by #7985
Closed

Type error caused by FormBuilderIterator #7984

dmaicher opened this issue Dec 8, 2022 · 2 comments · Fixed by #7985

Comments

@dmaicher
Copy link
Contributor

dmaicher commented Dec 8, 2022

Environment

  • PHP 8.1
  • latest Symfony 6.1
  • latest Sonata packages

Subject

Type error caused by FormBuilderIterator

Minimal repository with the bug

?

Steps to reproduce

I have an inline admin where I can add new items in a table view. If I press the "add" button then I get a type error since I moved to Symfony 6. It worked fine with Symfony 5.4 as there was no string typehint on Symfony's FormBuilder::get.

Actual results

Screenshot from 2022-12-08 13-09-45

A dump of

    public function current(): FormBuilderInterface
    {
        if ($this->iterator->current() === 0) {
            dd($this);
        }

        return $this->formBuilder->get($this->iterator->current());
    }

Screenshot from 2022-12-08 13-10-26

From what I can tell we cannot guarantee that $this->iterator->current() within FormBuilderIterator will actually be a string. In my case its an integer and this seems legit. The problematic form field is an expanded choice field with checkboxes and the children of this form are indexed with integers.

I checked it and casting to string there solves the issue for me. Shall I create a PR for this?

    public function current(): FormBuilderInterface
    {
        return $this->formBuilder->get((string) $this->iterator->current());
    }
@dmaicher
Copy link
Contributor Author

dmaicher commented Dec 8, 2022

Might be related to symfony/symfony#46698 @VincentLanglet 🤔

@VincentLanglet
Copy link
Member

Yeah, it was reported here sonata-project/form-extensions#368 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants