8000 [Validator] Typed property must not be accessed before initialization · Issue #35454 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Validator] Typed property must not be accessed before initialization #35454

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

Closed
greedyivan opened this issue Jan 23, 2020 · 0 comments
Closed

Comments

@greedyivan
Copy link
Contributor

Related: doctrine/orm#7944

Description:
This is the same issue when ReflectionProperty::getValue() uses an uninitialized argument.

How to reproduce:
Validate an object that has an uninitialized property with type hint:

    /**
     * @Assert\NotBlank()
     */
    public int $id;

Possible Solution:
Something similar to TypedNoDefaultReflectionProperty.php
Symfony\Component\Validator\Mapping\PropertyMetadata::getPropertyValue:

    /**
     * {@inheritdoc}
     */
    public function getPropertyValue($object)
    {
        $reflectionProperty = $this->getReflectionMember($object);

        return $object !== null && $reflectionProperty->isInitialized($object) ? $reflectionProperty->getValue($object) : null;
    }
@fabpot fabpot closed this as completed Jan 31, 2020
fabpot added a commit that referenced this issue Jan 31, 2020
…ing value (greedyivan)

This PR was squashed before being merged into the 3.4 branch (closes #35532).

Discussion
----------

[Validator] fix access to uninitialized property when getting value

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35454
| License       | MIT
| Doc PR        |

In PHP 7.4, the type-hinted property is [uninitialized](https://wiki.php.net/rfc/typed_properties_v2#uninitialized_and_unset_properties) by default. So it needs to be checked before use.

Commits
-------

1edecf7 [Validator] fix access to uninitialized property when getting value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0