Sylius: Closures being serialized by the form component ?

Created on 2 Dec 2016  路  6Comments  路  Source: Sylius/Sylius

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 https://github.com/Sylius/Sylius/blob/8a2e157498d11aece5b4f3beacdc9705dd01d91a/src/Sylius/Bundle/AddressingBundle/Form/Type/CountryChoiceType.php#L45)

Anybody encountered the same error ?
Thanks

Potential Bug

Most helpful comment

Yep, it is - Hope this will be tagged soon. Closing this one since it's not _Sylius-related_. Thanks for your help @michalmarcinkowski

All 6 comments

Thanks for reporting, we should definitely fix that. We will have a look at it soon! :)

Looks like symfony issue (https://github.com/symfony/symfony/issues/20698). Can you check if https://github.com/symfony/symfony/pull/20700 resolves it?

I have manually patched the related files in the merged PR but to no avail ..

@nicolas-grekas is going to work on a solution (https://github.com/symfony/symfony/issues/20698#issuecomment-264642928), let's move the discussion there.

Yep, it is - Hope this will be tagged soon. Closing this one since it's not _Sylius-related_. Thanks for your help @michalmarcinkowski

Was this page helpful?
0 / 5 - 0 ratings

Related issues

crbelaus picture crbelaus  路  3Comments

tchapi picture tchapi  路  3Comments

Chrysweel picture Chrysweel  路  3Comments

mezoni picture mezoni  路  3Comments

xleliberty picture xleliberty  路  3Comments