8000 Closures being serialized by the form component ? · Issue #6987 · Sylius/Sylius · GitHub
[go: up one dir, main page]

Skip to content
Closures being serialized by the form component ? #6987
@tchapi

Description

@tchapi

I have many errors like this one in the latest master on PHP 7 :

[2016-12-02 12:58:33] php.CRITICAL: Uncaught Exception: Serialization of 'Closure' is not allowed {"exception":"[object] (Exception(code: 0): Serialization of 'Closure' is not allowed at /vendor/zendframework/zend-stdlib/src/PriorityQueue.php:178)"} []

and no stack trace to try to find the error (the debugger does not load) :/

I have looked around what could be the problem and I found that the Form component might not like function closures for choices. Sonata reportedly had the same problem and they fixed it here (See related discussion here).

Not sure if the problem is in Sylius directly but it could be in code like this one :

public function configureOptions(OptionsResolver $resolver)
    {
        $resolver
            ->setDefaults([
                'choices' => function (Options $options) {
                    if (null === $options['enabled']) {
                        return $this->countryRepository->findAll();
                    }

                    return $this->countryRepository->findBy(['enabled' => $options['enabled']]);
                },
                'choice_value' => 'code',
                'choice_label' => 'name',
                'choice_translation_domain' => false,
                'enabled' => true,
                'label' => 'sylius.form.address.country',
                'placeholder' => 'sylius.form.country.select',
            ])
        ;
    }

(see for instance

'choices' => function (Options $options) {
)

Anybody encountered the same error ?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Potential BugPotential bugs or bugfixes, that needs to be reproduced.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0