Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] Any constraint on an array property causes traversing it #27090

Copy link
Copy link
Closed
@corphi

Description

@corphi
Issue body actions
Q A
Bug report? yes
Feature request? no
BC Break report? well…
RFC? no
Symfony version all since 2.5.0

While #23032 also deals with arrays, this bug is specific to traversing mixed hierarchies of arrays and objects. The issue is that arrays are added to the todo list for traversing if they carry any constraint. This behaviour has been introduced in the original implementation of RecursiveContextualValidator back in 2.5.0. Older versions behaved correctly (tested with latest 2.3). This is a BC break with unsupported versions, I’m not sure if it qualifies.

Minimal test scenario:

<?php
class Foo
{
     /** @Assert\Count(min=1, max=1) */
    public $bars;
    public function __construct()
    {
        $this->bars = array(new Bar());
    }
}
class Bar
{
    /** @Assert\NotBlank */
    public $baz;
}
$validator->validate(new Foo());

If the Count constraint is removed, validation passes, as validation does not traverse $bars by default.

I created a failing test that also works below 2.5.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.