Skip to content

[PropertyAccess] #28966 introduces subtle change in behaviour #29340

Closed
@bendavies

Description

@bendavies

Symfony version(s) affected: 4.1.8

Description
#28966 fixing an issue where a model has 2 properties, the 2nd property name being the plural form of the first.

The fix introduced a change in behaviour when a model has a collection property, that has a setter and an adder+remover defined.

class Foo
{
    private $invoices = [];

    public function setInvoices(array $invoices): void
    {
        //...
    }

    public function addInvoice(Invoice $invoice): void
    {
        //...
    }

    public function removeInvoice(Invoice $item): void
    {
        //...
    }
}

If setting the invoices collection:

It could be said that if your model is depending on an order here, your model probably has a bug.
In fact, the change of behaviour did indeed highlighted a bug in my model, so I'm grateful for that!

Regardless, is this an intended, acceptable behaviour change for collection properties?

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