Skip to content

[PropertyAccessor] Fix unable to write to singular property using setter while plural adder/remover exist #28966

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

Conversation

karser
Copy link
Contributor

@karser karser commented Oct 24, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #28961
License MIT

Please take a look at the tests I added - they describe the issue. It has to do with the priorities: findAdderAndRemover('User', 'email') is called earlier than $this->isMethodAccessible('User', 'setEmail', 1)

@nicolas-grekas nicolas-grekas changed the title [PropertyAccessor][php5] Fix unable to write to singular property using setter while plural adder/remover exist [PropertyAccessor] Fix unable to write to singular property using setter while plural adder/remover exist Oct 24, 2018
@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Oct 24, 2018
@karser
Copy link
Contributor Author

karser commented Oct 31, 2018

@nicolas-grekas This bug exists in 4.1 and master, is this PR going to be merged in there as well?

@nicolas-grekas
Copy link
Member

@karser yes: we regularly merge lower branches into upper ones.

@nicolas-grekas
Copy link
Member

Thank you @karser.

@nicolas-grekas nicolas-grekas merged commit 8238f16 into symfony:3.4 Nov 15, 2018
nicolas-grekas added a commit that referenced this pull request Nov 15, 2018
…y using setter while plural adder/remover exist (karser)

This PR was merged into the 3.4 branch.

Discussion
----------

[PropertyAccessor] Fix unable to write to singular property using setter while plural adder/remover exist

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #28961
| License       | MIT

Please take a look at the tests I added - they describe the issue. It has to do with the priorities: `findAdderAndRemover('User', 'email')` is called earlier than `$this->isMethodAccessible('User', 'setEmail', 1)`

Commits
-------

8238f16 [PropertyAccessor] Fix unable to write to singular property using setter while plural adder/remover exist
@fabpot fabpot mentioned this pull request Nov 16, 2018
This was referenced Nov 26, 2018
@bendavies
Copy link
Contributor

bendavies commented Nov 26, 2018

I think we have a problem here which has caused a regression, or at least a change in behaviour.

If you have a collection property which has a setter, an adder and a remover:

class Foo
{
    private $invoices = [];

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

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

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

prior to this change, the adder/remover were used over the setter, but with this change, the setter is prioritized over the adder/remover.

Yes, setInvoices should behave identically to removeInvoice(),addInvoice(), but the change in behaviour is there regardless.

Is this an intended, acceptable consequence?

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

Successfully merging this pull request may close these issues.

4 participants