8000 5.4.0-BETA3 regression, Argument #2 ($haystack) must be of type array, null given · Issue #44182 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

5.4.0-BETA3 regression, Argument #2 ($haystack) must be of type array, null given #44182

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

Closed
PhilETaylor opened this issue Nov 21, 2021 · 16 comments · Fixed by #44188
Closed

5.4.0-BETA3 regression, Argument #2 ($haystack) must be of type array, null given #44182

PhilETaylor opened this issue Nov 21, 2021 · 16 comments · Fixed by #44188

Comments

@PhilETaylor
Copy link
Contributor
PhilETaylor commented Nov 21, 2021

Symfony version(s) affected

5.4.0-BETA3

Description

Im really sorry I dont have a lot of information on why this is happening, but Im open and responsive if you have specific questions.

Normally, my app is totally exception free. After upgrading to Symfony 5.4 Beta3 I get this exception thrown when submitting a form that works fine in Symfony 5.3

Im hoping someone closer to the code might spot the regression from the stack trace.

TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given
#28 /vendor/symfony/validator/Constraint.php(236): in_array
#27 /vendor/symfony/validator/Constraint.php(236): Symfony\Component\Validator\Constraint::addImplicitGroupName
#26 /vendor/symfony/validator/Mapping/ClassMetadata.php(222): Symfony\Component\Validator\Mapping\ClassMetadata::addConstraint
#25 /vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php(52): Symfony\Component\Validator\Mapping\Loader\AnnotationLoader::loadClassMetadata
#24 /vendor/symfony/validator/Mapping/Loader/LoaderChain.php(54): Symfony\Component\Validator\Mapping\Loader\LoaderChain::loadClassMetadata
#23 /vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php(101): Symfony\Component\Validator\Mapping\Factory\LazyLoadingMetadataFactory::getMetadataFor
#22 /vendor/symfony/validator/Validator/RecursiveContextualValidator.php(306): Symfony\Component\Validator\Validator\RecursiveContextualValidator::validateObject
#21 /vendor/symfony/validator/Validator/RecursiveContextualValidator.php(138): Symfony\Component\Validator\Validator\RecursiveContextualValidator::validate
#20 /vendor/symfony/form/Extension/Validator/Constraints/FormValidator.php(108): Symfony\Component\Form\Extension\Validator\Constraints\FormValidator::validate
#19 /vendor/symfony/validator/Validator/RecursiveContextualValidator.php(759): Symfony\Component\Validator\Validator\RecursiveContextualValidator::validateInGroup
#18 /vendor/symfony/validator/Validator/RecursiveContextualValidator.php(488): Symfony\Component\Validator\Validator\RecursiveContextualValidator::validateClassNode
#17 /vendor/symfony/validator/Validator/RecursiveContextualValidator.php(313): Symfony\Component\Validator\Validator\RecursiveContextualValidator::validateObject
#16 /vendor/symfony/validator/Validator/RecursiveContextualValidator.php(138): Symfony\Component\Validator\Validator\RecursiveContextualValidator::validate
#15 /vendor/symfony/validator/Validator/RecursiveValidator.php(93): Symfony\Component\Validator\Validator\RecursiveValidator::validate
#14 /vendor/symfony/form/Extension/Validator/EventListener/ValidationListener.php(50): Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener::validateForm
#13 /vendor/symfony/event-dispatcher/EventDispatcher.php(230): Symfony\Component\EventDispatcher\EventDispatcher::callListeners
#12 /vendor/symfony/event-dispatcher/EventDispatcher.php(59): Symfony\Component\EventDispatcher\EventDispatcher::dispatch
#11 /vendor/symfony/event-dispatcher/ImmutableEventDispatcher.php(33): Symfony\Component\EventDispatcher\ImmutableEventDispatcher::dispatch
#10 /vendor/symfony/form/Form.php(681): Symfony\Component\Form\Form::submit
#9 /vendor/symfony/form/Extension/HttpFoundation/HttpFoundationRequestHandler.php(109): Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler::handleRequest
#8 /vendor/symfony/form/Form.php(503): Symfony\Component\Form\Form::handleRequest
#7 /vendor/philetaylor/base/src/Controller/Account/TeamsController.php(225): Base\Controller\Account\TeamsController::handleRequest
#6 /vendor/philetaylor/base/src/Controller/Account/TeamsController.php(115): Base\Controller\Account\TeamsController::edit
#5 /vendor/symfony/http-kernel/HttpKernel.php(152): Symfony\Component\HttpKernel\HttpKernel::handleRaw
#4 /vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel::handle
#3 /vendor/symfony/http-kernel/Kernel.php(202): Symfony\Component\HttpKernel\Kernel::handle
#2 /vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php(37): Symfony\Component\Runtime\Runner\Symfony\HttpKernelRunner::run
#1 /vendor/autoload_runtime.php(35): require_once
#0 /public/index.php(21): null

The form is very basic with name, username, email and multiple submit buttons.

How to reproduce

Im really sorry I dont have a lot of information on why this is happening, but Im open and responsive if you have specific questions.

This also happens when users try to register with my app...

Possible Solution

No response

Additional Context

PHP 8.0.13

@derrabus
Copy link
Member

Could this be caused by #44037, @nicolas-grekas?

@PhilETaylor
Copy link
Contributor Author

Just one other bit of information that might help is that it was not experienced in 5.4.0-BETA2 and only started with 5.4.0-BETA3

@derrabus
Copy link
Member

Can you provide some insights on which validation constraints are used by your form? Do you use any custom contraints?

@PhilETaylor
Copy link
Contributor Author
PhilETaylor commented Nov 21, 2021

Some other comments about "groups" here #44138 (comment) and #44138 (comment)

@PhilETaylor
Copy link
Contributor Author
PhilETaylor commented Nov 21, 2021

Can you provide some insights on which validation constraints are used by your form? Do you use any custom contraints?

The contraints come from the User entity - there are only 2.

    /**
     * @Assert\Length(
     *     min=8,
     *     max=4096,
     *     minMessage="The password is too short",
     *     groups={"Profile", "ResetPassword", "Registration", "ChangePassword"}
     * )
     */
    private $plainPassword;

    /**
     * @Assert\Email(
     *     message="The email '{{ value }}' is not a valid email.",
     *     mode="strict"
     * )
     * @ORM\Column(type="string", length=180, nullable=false)
     */
    private $email;

nicolas-grekas added a commit that referenced this issue Nov 22, 2021
…when __sleep() is implemented (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[VarExporter] fix exporting declared but unset properties when __sleep() is implemented

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #44138 Fix #44182
| License       | MIT
| Doc PR        | -

Best reviewed [ignoring whitespaces](https://github.com/symfony/symfony/pull/44188/files?w=1).

Commits
-------

a557bdc [VarExporter] fix exporting declared but unset properties when __sleep() is implemented
@nicolas-grekas
Copy link
Member

Fixed by #44188

@PhilETaylor
Copy link
Contributor Author

Thanks @nicolas-grekas - really appreciate your work.

@bobvandevijver
Copy link
Contributor

@nicolas-grekas I'm now seeing this issue on a 4.4 project, which I just updated to the latest release (4.4.34):

24) App\Tests\Sale\SaleServiceTest::test_transaction_negative_result
TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given

/var/www/007-stores-dev/vendor/symfony/validator/Constraint.php:229
/var/www/007-stores-dev/vendor/symfony/validator/Mapping/ClassMetadata.php:192
/var/www/007-stores-dev/vendor/symfony/validator/Mapping/Loader/AnnotationLoader.php:51
/var/www/007-stores-dev/vendor/symfony/validator/Mapping/Loader/LoaderChain.php:54
/var/www/007-stores-dev/vendor/symfony/validator/Mapping/Factory/LazyLoadingMetadataFactory.php:124
/var/www/007-stores-dev/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:308
/var/www/007-stores-dev/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:138
/var/www/007-stores-dev/vendor/symfony/validator/Validator/RecursiveValidator.php:93
/var/www/007-stores-dev/vendor/symfony/validator/Validator/TraceableValidator.php:66
/var/www/007-stores-dev/src/Sale/SaleService.php:325
/var/www/007-stores-dev/src/Service/DescriptorService.php:289
/var/www/007-stores-dev/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:247
/var/www/007-stores-dev/src/Service/DescriptorService.php:292
/var/www/007-stores-dev/src/Service/DescriptorService.php:217
/var/www/007-stores-dev/src/Sale/SaleService.php:350
/var/www/007-stores-dev/tests/phpunit/Sale/SaleServiceTest.php:616
/var/www/007-stores-dev/vendor/phpunit/phpunit/phpunit:92

@nicolas-grekas
Copy link
Member

What is your version of symfony/var-exporter please?
Does this happen even if you remove your var/cache folder by hand?
Please provide a reproducer if you can.

@stof
Copy link
Member
stof commented Nov 22, 2021

@bobvandevijver is this happening with a clean cache or do you have a cache created with the old version of Symfony ?

@bobvandevijver
Copy link
Contributor

I actually updated to the latest var-exporter (v4.4.34) as otherwise it spammed the following line:

PHP Notice:  serialize(): "groups" returned as member variable from __sleep() but does not exist in /var/www/007-stores-dev/vendor/symfony/var-exporter/Internal/Exporter.php on line 165

But, somehow, the issue disappeared. I was sure I cleared the cache fully, but I guess I cleared the wrong one (dev instead of test). Sorry for that!

@nicolas-grekas
Copy link
Member

Thanks for the feedback, closing then.

@amacrobert-meq
Copy link
amacrobert-meq commented Nov 29, 2021

I am reproducing this issue on 5.4.0. I have deleted var/cache/* manually to no avail.

$ composer show symfony/var-exporter:

name     : symfony/var-exporter
descrip. : Allows exporting any serializable PHP data structure to plain PHP code
keywords : clone, construct, export, hydrate, instantiate, serialize
versions : * v5.4.0
type     : library
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : https://symfony.com
source   : [git] https://github.com/symfony/var-exporter.git d59446d6166b1643a8a3c30c2fa8e16e51cdbde7
dist     : [zip] https://api.github.com/repos/symfony/var-exporter/zipball/d59446d6166b1643a8a3c30c2fa8e16e51cdbde7 d59446d6166b1643a8a3c30c2fa8e16e51cdbde7
path     : /home/wwwroot/mymeq/vendor/symfony/var-exporter
names    : symfony/var-exporter

support
source : https://github.com/symfony/var-exporter/tree/v5.4.0

autoload
psr-4
Symfony\Component\VarExporter\ => .
exclude-from-classmap

requires
php >=7.2.5
symfony/polyfill-php80 ^1.16

requires (dev)
symfony/var-dumper ^4.4.9|^5.0.9|^6.0

$ php -v:

PHP 8.0.13 (cli) (built: Nov 19 2021 21:41:50) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.13, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies

Here's my trace:

1) Tests\App\Controller\Json\Authentication\RegistrationControllerTest::testRegisterUnverifiedDirect
TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given

/home/wwwroot/mymeq/vendor/symfony/form/Extension/Validator/Constraints/FormValidator.php:126
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:759
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:602
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:117
/home/wwwroot/mymeq/vendor/symfony/form/Extension/Validator/Constraints/FormValidator.php:145
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:759
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:488
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:313
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveContextualValidator.php:138
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/RecursiveValidator.php:93
/home/wwwroot/mymeq/vendor/symfony/validator/Validator/TraceableValidator.php:66
/home/wwwroot/mymeq/vendor/symfony/form/Extension/Validator/EventListener/ValidationListener.php:50
/home/wwwroot/mymeq/vendor/symfony/event-dispatcher/EventDispatcher.php:230
/home/wwwroot/mymeq/vendor/symfony/event-dispatcher/EventDispatcher.php:59
/home/wwwroot/mymeq/vendor/symfony/event-dispatcher/ImmutableEventDispatcher.php:33
/home/wwwroot/mymeq/vendor/symfony/form/Form.php:681
/home/wwwroot/mymeq/src/Controller/Json/Authentication/RegistrationController.php:545
/home/wwwroot/mymeq/vendor/symfony/http-kernel/HttpKernel.php:152
/home/wwwroot/mymeq/vendor/symfony/http-kernel/HttpKernel.php:74
/home/wwwroot/mymeq/vendor/symfony/http-kernel/Kernel.php:202
/home/wwwroot/mymeq/vendor/symfony/http-kernel/HttpKernelBrowser.php:65
/home/wwwroot/mymeq/vendor/symfony/framework-bundle/KernelBrowser.php:177
/home/wwwroot/mymeq/vendor/symfony/browser-kit/AbstractBrowser.php:398
/home/wwwroot/mymeq/tests/Controller/Json/AbstractControllerTest.php:320
/home/wwwroot/mymeq/tests/Controller/Json/AbstractControllerTest.php:381
/home/wwwroot/mymeq/tests/Controller/Json/Authentication/RegistrationControllerTest.php:242

@bobvandevijver
Copy link
Contributor

@amacrobert-meq As it looks to be tests for you as well, try to run bin/console cache:clear -e test, that seemed to solve it for me.

@amacrobert-meq
Copy link

Thanks but that didn't help (nor did deleting var/cache/test). It looks like our issues are coming from similar but different places. I wonder if 5.4.0 / 4.4.34 fixed it in one but not both places.

Making this change in /vendor/symfony/form/Extension/Validator/Constraints/FormValidator.php line 126 solves:

                     foreach ($groups as $group) {
 -                       if (\in_array($group, $constraint->groups)) {
 +                       if (\in_array($group, $constraint->groups ?? [])) {
                             $groupedConstraints[$group][] = $constraint;

...but I'm not sure if the real issue is caused upstream, and of course I don't want vendor patches in production.

@amacrobert-meq
Copy link
amacrobert-meq commented Nov 29, 2021

Alright I fixed in my app code. The $constraint that was failing was a custom constraint that extends Symfony\Component\Validator\Constraint. Adding $this->groups = []; to its constructor solved the issue.

EDIT: Better fix was to call the parent constructor.

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