Skip to content

Serializing methods in all lowercase works differently in latest 7.1 and 7.2 #58876

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
tacman opened this issue Nov 14, 2024 · 6 comments
Closed

Comments

@tacman
Copy link
Contributor

tacman commented Nov 14, 2024

Symfony version(s) affected

7.2

Description

I used to be able to serialize the method getrp() in lowercase. Now it doesn't serialize unless I rename it to getRp().

How to reproduce

    #[Groups(['rp', 'transitions', 'searchable'])]
    public function getrp(?array $addlParams = []): array
    {
        return array_merge($this->getUniqueIdentifiers(), $addlParams);
    }

This serializes with 7.0 and until recently, 7.1. It no longer works.

Possible Solution

In 7.0, AttributeLoader.php looked line this:

            $accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
            if ($accessorOrMutator) {
                $attributeName = lcfirst($matches[2]);

                if (isset($attributesMetadata[$attributeName])) {
                    $attributeMetadata = $attributesMetadata[$attributeName];
                } else {
                    $attributesMetadata[$attributeName] = $attributeMetadata = new AttributeMetadata($attributeName);
                    $classMetadata->addAttributeMetadata($attributeMetadata);
                }
            }

Recently, it changed:

            $accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
            if ($accessorOrMutator && !ctype_lower($matches[2][0])) {
                $attributeName = lcfirst($matches[2]);

                if (isset($attributesMetadata[$attributeName])) {
                    $attributeMetadata = $attributesMetadata[$attributeName];
                } else {
                    $attributesMetadata[$attributeName] = $attributeMetadata = new AttributeMetadata($attributeName);
                    $classMetadata->addAttributeMetadata($attributeMetadata);
                }
            }

Additional Context

No response

@tacman
Copy link
Contributor Author

tacman commented Nov 14, 2024

Perhaps related to #58705

@xabbuh
Copy link
Member

xabbuh commented Nov 14, 2024

#56868 is the PR that introduced this change (see the bug described in #58652 for the motivation behind the change)

@tacman
Copy link
Contributor Author

tacman commented Nov 14, 2024

Thanks. Like the OP for the canCel bug, it took a while to hunt this one down.

@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 ping? Should this still be open? I will close if I don't hear anything.

@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!

@carsonbot carsonbot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2025
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

3 participants