Skip to content

[HttpFoundation] do not access properties before initialization #51904

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
Oct 10, 2023

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Oct 9, 2023

Q A
Branch? 7.0
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT

@stof
Copy link
Member

stof commented Oct 9, 2023

the right solution is actually to add a null default value there (otherwise, we break BC for child classes)

@xabbuh
Copy link
Member Author

xabbuh commented Oct 9, 2023

changed it to initialise the properties with null instead


protected static ?\Closure $requestFactory = null;

private string $preferredFormat;
private ?string $preferredFormat = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this one needs to be changed. As it is a private method, we can fully control the lazy initialization and the code handling it was fine (as we use ??=)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can keep it as is, but then we need to update getPreferredFormat() to not assign null to this property (changes pushed)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, I missed that we were sometimes assigning null

@fabpot
Copy link
Member

fabpot commented Oct 10, 2023

Thank you @xabbuh.

@fabpot fabpot merged commit 74b4bbd into symfony:7.0 Oct 10, 2023
@xabbuh xabbuh deleted the pr-51069 branch October 10, 2023 06:46
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.

4 participants