Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix order array sum normalizedData and nestedData#51825

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@jerowork
Copy link
Contributor

@jeroworkjerowork commentedOct 3, 2023
edited
Loading

QA
Branch?6.3
Bug fix?yes
New feature?no
Deprecations?no
Tickets#51823
LicenseMIT

Description

With the update of Serializer to 6.3.5, some deserialization of array to objects does behave differently (changed order of priority of configuration via attribute#[SerializedPath] vs. property name, when there is a key on root level with the same name as the private property.

Related to#49700.

How to reproduce

Example to explain changed behavior:

{"data": {"item": {"id":"id-1"    }  },"id":"id-2"}
finalclass SomeEvent{    #[SerializedPath('[data][item][id]')]publicstring$id;}

Before 6.3.5, the value of the id wasid-1, with the change of#49700, the value of the id becomesid-2.

#49700 changesarray_merge witharray + array. It seems that the problem stated above is related to the fact that array_merge does overwrite keys differently than array + array:

$a = ['key' =>'value-a'];$b = ['key' =>'value-b'];var_dump(array_merge($a,$b));// Results in:// array(1) {//   ["key"]=>//   string(7) "value-b"// }var_dump($a +$b);// Results in:// array(1) {//   ["key"]=>//   string(7) "value-a"// }

Solution

Asarray_merge does behave slightly differently that array + array, the solution could be to switch array order to:

- $normalizedData = $normalizedData + $nestedData;+ $normalizedData = $nestedData + $normalizedData;

This would result in the same, while keeping the fix (#49700) for the numeric key value

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

jerowork reacted with thumbs up emoji

@jeroworkjerowork marked this pull request as ready for reviewOctober 3, 2023 08:11
@carsonbotcarsonbot added this to the6.3 milestoneOct 3, 2023
@carsonbot
Copy link

Hey!

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

Symfony has acontribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (seehttps://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (seehttps://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.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

Previously, when `array_merge` was changed array+array in 6.3.5, the combinedarray result is changed as well. array_merge behaves differently than array+array.e.g.:```$a = ['key' => 'value-a'];$b = ['key' => 'value-b'];var_dump(array_merge($a, $b));// Results in:// array(1) {//   ["key"]=>//   string(7) "value-b"// }var_dump($a + $b);// Results in:// array(1) {//   ["key"]=>//   string(7) "value-a"// }```By switching left with right, the result will be the same again.
@jeroworkjeroworkforce-pushed thejerowork/fix/change-order-array-plus-on-object-deserialization branch from158ca81 to67f49d4CompareOctober 3, 2023 08:16
@jeroworkjerowork changed the titleFix order array sum normalizedData and nestedData[Serializer] Fix order array sum normalizedData and nestedDataOct 3, 2023
@HypeMC
Copy link
Member

I've encountered the same issue and can confirm that this fixes it without (at least in my case) introducing any additional problems.

@carsonbotcarsonbot changed the title[Serializer] Fix order array sum normalizedData and nestedDataFix order array sum normalizedData and nestedDataOct 7, 2023
@fabpot
Copy link
Member

Thank you@jerowork.

jerowork reacted with thumbs up emojiruudk reacted with hooray emoji

@fabpotfabpot merged commitbfd2f7d intosymfony:6.3Oct 7, 2023
@fabpotfabpot mentioned this pull requestOct 21, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@OskarStarkOskarStarkOskarStark approved these changes

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.3

Development

Successfully merging this pull request may close these issues.

5 participants

@jerowork@carsonbot@HypeMC@fabpot@OskarStark

[8]ページ先頭

©2009-2025 Movatter.jp