Skip to content
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

[Serializer] Inconsistent Naming of First Argument in normalize() Method between NormalizerInterface and Serializer Class #54774

Open
russelomua opened this issue Apr 29, 2024 · 0 comments · May be fixed by #54880
Labels
Bug DX DX = Developer eXperience (anything that improves the experience of using Symfony) Serializer Status: Needs Review

Comments

@russelomua
Copy link

Symfony version(s) affected

5.0-7.1

Description

The normalize() method in the Symfony\Component\Serializer\Normalizer\NormalizerInterface interface has the first argument named object, yet in the class implementing this interface, Symfony\Component\Serializer\Serializer, the first argument is called data. This discrepancy prevents the use of a named argument.

Fatal error: Uncaught Error: Unknown named parameter $object

How to reproduce

use Symfony\Component\Serializer\Normalizer\NormalizerInterface;

class DummyService {
    public function __construct(private readonly NormalizerInterface $normalizer) {}

    public summy($object): array
    {
        return $this->normalizer->normalize(
            object: $value, 
            context: [
                'some' => 'context'
            ],
        );
    }
}

Possible Solution

Rename first argument of Symfony\Component\Serializer\Serializer::normalize() class as described in interface

Additional Context

Perhaps it's unlikely that anyone will use the named argument as the first parameter, but it does seem like an inconsistency in implementation, I suppose. Thanks.

@russelomua russelomua added the Bug label Apr 29, 2024
@xabbuh xabbuh added the DX DX = Developer eXperience (anything that improves the experience of using Symfony) label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug DX DX = Developer eXperience (anything that improves the experience of using Symfony) Serializer Status: Needs Review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants