8000 [Serializer] Take unnamed variadic parameters into account when denormalizing by thijsBreker · Pull Request #53361 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Take unnamed variadic parameters into account when denormalizing #53361

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

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

thijsBreker
Copy link
Contributor
@thijsBreker thijsBreker commented Jan 2, 2024

We shouldn't break when a constructor has variadic parameters without named keys in the array.

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

@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.1 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 [WIP] [Serializer] Take unnamed variadic parameters into account when denormalizing [Serializer] [WIP] Take unnamed variadic parameters into account when denormalizing Jan 2, 2024
@HypeMC
Copy link
Contributor
HypeMC commented Jan 3, 2024

This was caused by #53115, sorry about that. IMO, the best solution would be to avoid using named arguments when the function is variadic:

index 1a7c314b84..27224f5b3d 100644
--- a/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+++ b/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
@@ -372,7 +372,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
                             $variadicParameters[$parameterKey] = $this->denormalizeParameter($reflectionClass, $constructorParameter, $paramName, $parameterData, $context, $format);
                         }
 
-                        $params = array_merge($params, $variadicParameters);
+                        $params = array_merge(array_values($params), $variadicParameters);
                         $unsetKeys[] = $key;
                     }
                 } elseif ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) {

@thijsBreker
Copy link
Contributor Author

No worries! This gave me the chance to contribute for the first time :)

@thijsBreker
Copy link
Contributor Author

I don't understand where the code standard errors are coming from. The patch provided changes things that have been there since 2018?

@HypeMC
Copy link
Contributor
HypeMC commented Jan 3, 2024

I don't understand where the code standard errors are coming from. The patch provided changes things that have been there since 2018?

Don't worry about it, most are false positives. Just revert the coding standard changes on lines you didn't modify.

@HypeMC
Copy link
Contributor
HypeMC commented Jan 6, 2024

@thijsBreker It would be good to remove WIP from the title.

@thijsBreker thijsBreker changed the title [Serializer] [WIP] Take unnamed variadic parameters into account when denormalizing [Serializer] Take unnamed variadic parameters into account when denormalizing Jan 8, 2024
…malizing

We shouldn't break when a constructor has variadic parameters without
named keys in the array.
@nicolas-grekas
Copy link
Member

Thank you @thijsBreker.

@nicolas-grekas nicolas-grekas merged commit 2b7706a into symfony:5.4 Jan 29, 2024
@thijsBreker thijsBreker deleted the fix_53354 branch January 29, 2024 08:41
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.

5 participants
0