Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyAccess] BC break on getsetter order #37260

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
dragosprotung opened this issue Jun 12, 2020 · 11 comments
Closed

[PropertyAccess] BC break on getsetter order #37260

dragosprotung opened this issue Jun 12, 2020 · 11 comments

Comments

@dragosprotung
Copy link
Contributor

Symfony version(s) affected: 5.1.0+

Description

Prior to 5.1.0 the getsetter method was checked second after getter.
See https://github.com/symfony/symfony/blob/v5.0.9/src/Symfony/Component/PropertyAccess/PropertyAccessor.php#L479-L482 for prior logic.

After moving the logic into the PropertyInfo component get getsetter is checked after prefixed accessors.
See https://github.com/symfony/property-info/blob/master/Extractor/ReflectionExtractor.php#L239-L253

How to reproduce

Given the following class

class Order
{
    private array $payments = [];

    public function payments(): array
    {
        return $this->payments;
    }

    public function hasPayments(): bool
    {
        return count($this->payments) > 0;
    }
}

trying to access payments will return a boolean value instead of the the array by accessing the hasPayments() instead of the payments() method.

@nicolas-grekas
Copy link
Member

Can you try 5.1.1?

@dragosprotung
Copy link
Contributor Author

Same issue

@xabbuh
Copy link
Member

xabbuh commented Jun 12, 2020

#37053 does not fix this?

@dragosprotung
Copy link
Contributor Author

Unfortunately not. That issue is related to prefixed accessors (getters, setters, hassers) but not when there is no prefix (getsetter).

In Symfony prior to 5.1.0 the order was: getter, getsetter, etc
In Symfony 5.1.0+ the order is: getter, is, has, can and then getsetter

@dragosprotung
Copy link
Contributor Author

@xabbuh is any more feedback needed ?

@xabbuh
Copy link
Member

xabbuh commented Jun 18, 2020

I didn't try it out but your last comment reads like one should be able to reproduce what you reported now.

@dragosprotung
Copy link
Contributor Author

I would like to work on fixing this, but it will require to stop using the accessorPrefixes property and get rid of the default defaultAccessorPrefixes. The fix is not particularly hard, but requires a change that will break current implementation. Any guidance is appreciated.

@xabbuh
Copy link
Member

xabbuh commented Jun 26, 2020

Sounds like that's the way to go.

@carsonbot
Copy link

Hey, thanks for your report!
There has not been a lot of activity here for a while. Is this bug still relevant? Have you managed to find a workaround?

@carsonbot
Copy link

Friendly reminder that this issue exists. If I don't hear anything I'll close this.

@carsonbot
Copy link

Hey,

I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen!

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

No branches or pull requests

4 participants