8000 [Validator] PHP 7.4 uninitialized typed property handling by SpiGAndromeda · Pull Request #14376 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

[Validator] PHP 7.4 uninitialized typed property handling #14376

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 8, 2021
Merged

[Validator] PHP 7.4 uninitialized typed property handling #14376

merged 1 commit into from
Jan 8, 2021

Conversation

SpiGAndromeda
Copy link
Contributor

The Validator component is able to handle uninitialized properties since this PR was merged.

However, the behavior (null usage) is not documented in the symfony docs.

P.S. PR 14375 was closed due to wrong source branch.

@wouterj
Copy link
Member
wouterj commented Oct 22, 2020

Hi @SpiGAndromeda! Thanks for the PR and detailed references to relevant PRs.

However, I'm not so sure if this is something that has to be documented. Won't this "just work"? In other words, are there situations where this behavior would be inconsistent with what people are expecting? If there is, we should document those (and show how to avoid it). Otherwise, I would vote to not document this change.

@SpiGAndromeda
Copy link
Contributor Author

@wouterj It can be problematic if you want to base some logic (e.g. for PATCH request handling) on the uninitialized state. If I would apply the NotNull constraint, it would return true even if the property is uninitialized but not null.

That PATCH requests are ugly and you maybe should not rely on the uninitialized state is another matter but could be mentioned.

@wouterj
Copy link
Member
wouterj commented Oct 23, 2020

Aha, thanks for clarifying @SpiGAndromeda.

It makes sense to document this now. I would suggest changing the contents slightly, not warn users about this unexpected behavior. E.g. something like:

.. caution::

    The validator will use a value ``null`` if a typed property is uninitialized. This can
    cause unexpected behavior if the property holds a value when initialized. In order
    to avoid this, make sure all properties are initialized before validating it.

What do you think?

@carsonbot carsonbot changed the title PHP 7.4 uninitialized typed property handling [Validator] PHP 7.4 uninitialized typed property handling Jan 8, 2021
@javiereguiluz javiereguiluz added this to the 4.4 milestone Jan 8, 2021
@javiereguiluz javiereguiluz changed the base branch from 3.4 to 4.4 January 8, 2021 16:34
@javiereguiluz javiereguiluz merged commit 424c4ef into symfony:4.4 Jan 8, 2021
@javiereguiluz
Copy link
Member

@SpiGAndromeda while merging we opted for the reword proposed by Wouter, but thanks for this contribution and for helping us to improve this. Congrats on your first Symfony Docs contribution too 🎉

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
0