Skip to content

Conversation

RafaelKr
Copy link

@RafaelKr RafaelKr commented Jul 10, 2025

Q A
Branch? 6.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #61096
License MIT

Notes

Although technically this is a bugfix and its pretty much an edge-case, this may affect existing projects and may alter their serialization results. So it could be a breaking change.

Edit: Also see comments below for further edge cases.

Before/After comparison

class MyClass {
  private string $owner = 'foo';
  private bool $isOwner = true;

  public function getOwner(): string {
    return $this->owner;
  }

  public function setOwner(string $owner): void {
    $this->owner = $owner;
  }

  public function isOwner(): bool {
    return $this->isOwner;
  }

  public function setIsOwner(bool $isOwner): void {
    $this->isOwner = $isOwner;
  }
}

$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$normalizer = new ObjectNormalizer($classMetadataFactory);

$object = new MyClass();
$normalized = $normalizer->normalize($object);

Before this PR

It was normalized as:

[
  'owner' => 'foo',
]

Removing the $owner property and getters would result in:

[
  'owner' => true,
]

After this PR

It will be normalized as:

[
  'owner' => 'foo',
  'isOwner'  => true,
]

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot carsonbot changed the title [Serializer][ObjectNormalizer] Fix isser methods where the property has the same name [Serializer] [ObjectNormalizer] Fix isser methods where the property has the same name Jul 10, 2025
@RafaelKr
Copy link
Author

RafaelKr commented Jul 10, 2025

Another Edge-Case

After I just found #61023 I also tried having properties and getter methods called isFoo and canFoo (no getFoo at this time) in the ObjectWithBooleanPropertyAndIsserWithSameName class:

class ObjectWithBooleanPropertyAndIsserWithSameName
{
    private $foo = 'foo';

    private $isFoo = true;

    private $canFoo = false;

    public function isFoo()
    {
        return $this->isFoo;
    }

    public function canFoo()
    {
        return $this->canFoo;
    }
}

This results in

[
  'isFoo' => true,
  'foo' => true, // it's using the isFoo isser method!
]

Notice, that for the canFoo property it's using the isFoo method to get the value and prints foo as result name.

Reading through the linked PR I wonder if my PR also classifies as "new feature" instead of "bugfix"?
cc @nicolas-grekas

@RafaelKr
Copy link
Author

RafaelKr commented Jul 10, 2025

Extended Edge-Case

class ObjectWithBooleanPropertyAndIsserWithSameName
{
    public $foo = 'foo';

    private $getFoo = 'getFoo';

    private $hasFoo = 'hasFoo';

    private $canFoo = 'canFoo';

    private $isFoo = 'isFoo';

    public function getFoo()
    {
        return $this->getFoo;
    }

    public function hasFoo()
    {
        return $this->hasFoo;
    }

    public function canFoo()
    {
        return $this->canFoo;
    }

    public function isFoo()
    {
        return $this->isFoo;
    }
}

Results in

[
  'foo' => 'getFoo',
  'isFoo' => 'isFoo'
]

So we may also want to add the $reflClass->hasProperty($name) check I added for issers for get, has and can?

That would result in:

[
    'getFoo' => 'getFoo',
    'hasFoo' => 'hasFoo',
    'canFoo' => 'canFoo',
    'isFoo' => 'isFoo',
    'foo' => 'getFoo'
]

@RafaelKr RafaelKr marked this pull request as draft July 10, 2025 15:08
@RafaelKr
Copy link
Author

RafaelKr commented Aug 4, 2025

What do you think, how should we proceed here? Should we do the hasProperty check I added for issers for all getter-like methods? Then we would do the check for:

  • getters
  • hassers
  • canners
  • issers

IMO it would definitely make sense for has, can and is. For get it's debatable.

@RafaelKr RafaelKr marked this pull request as ready for review August 4, 2025 10:55
@fabpot
Copy link
Member

fabpot commented Aug 4, 2025

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@RafaelKr RafaelKr changed the title [Serializer] [ObjectNormalizer] Fix isser methods where the property has the same name [Serializer] [ObjectNormalizer] Fix getter-like methods (isser, hasser, canner) where the property has the same name Aug 4, 2025
@RafaelKr RafaelKr changed the title [Serializer] [ObjectNormalizer] Fix getter-like methods (isser, hasser, canner) where the property has the same name [Serializer] [ObjectNormalizer] Fix isser methods where the property has the same name Aug 4, 2025
@OskarStark OskarStark changed the title [Serializer] [ObjectNormalizer] Fix isser methods where the property has the same name [Serializer][ObjectNormalizer] Fix isser methods where the property has the same name Aug 4, 2025
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.

3 participants