Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Property access broken in latest update #45233

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
garak opened this issue Jan 29, 2022 · 11 comments
Closed

Property access broken in latest update #45233

garak opened this issue Jan 29, 2022 · 11 comments

Comments

@garak
Copy link
Contributor

garak commented Jan 29, 2022

Symfony version(s) affected

5.4.3, 6.0.3

Description

I need to fix my dep to "symfony/property-access": "5.4.2" (or 6.0.2) after yesterday updates.
Otherwise, I get plenty of Typed property $foo must not be accessed before initialization

How to reproduce

See above

Possible Solution

No response

Additional Context

No response

@jderusse
Copy link
Member

could you please provide a reproducer?

@that-guy-iain
Copy link
Contributor

that-guy-iain commented Jan 29, 2022

I'm experiencing this issue as well. Here is a stack trace. On a form submission with a data class with class members that are type hinted.

      Behat\Testwork\Call\Exception\FatalThrowableError: Fatal error: Typed property Parthenon\User\Entity\User::$email must not be accessed before initialization in src/Parthenon/User/Entity/User.php:54
      Stack trace:
      #0 vendor/symfony/property-access/PropertyAccessor.php(402): Parthenon\User\Entity\User->getEmail()
      #1 vendor/symfony/property-access/PropertyAccessor.php(115): Symfony\Component\PropertyAccess\PropertyAccessor->readProperty()
      #2 vendor/symfony/form/Extension/Core/DataAccessor/PropertyPathAccessor.php(91): Symfony\Component\PropertyAccess\PropertyAccessor->getValue()
      #3 vendor/symfony/form/Extension/Core/DataAccessor/PropertyPathAccessor.php(67): Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor->getPropertyValue()
      #4 vendor/symfony/form/Extension/Core/DataAccessor/ChainAccessor.php(54): Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor->setValue()
      #5 vendor/symfony/form/Extension/Core/DataMapper/DataMapper.php(79): Symfony\Component\Form\Extension\Core\DataAccessor\ChainAccessor->setValue()
      #6 vendor/symfony/form/Form.php(603): Symfony\Component\Form\Extension\Core\DataMapper\DataMapper->mapFormsToData()
      #7 vendor/symfony/form/Extension/HttpFoundation/HttpFoundationRequestHandler.php(109): Symfony\Component\Form\Form->submit()
      #8 vendor/symfony/form/Form.php(464): Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler->handleRequest()
      #9 src/Parthenon/Common/RequestHandler/RedirectRequestHandler.php(30): Symfony\Component\Form\Form->handleRequest()
      #10 src/Parthenon/User/RequestProcessor/UserSignup.php(37): Parthenon\Common\RequestHandler\RedirectRequestHandler->handleForm()
      #11 src/Controller/UserController.php(40): Parthenon\User\RequestProcessor\UserSignup->process()
      #12 vendor/symfony/http-kernel/HttpKernel.php(152): App\Controller\UserController->signup()
      #13 vendor/symfony/http-kernel/HttpKernel.php(74): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
      #14 vendor/symfony/http-kernel/Kernel.php(202): Symfony\Component\HttpKernel\HttpKernel->handle()
      #15 vendor/symfony/http-kernel/HttpKernelBrowser.php(65): Symfony\Component\HttpKernel\Kernel->handle()
      #16 vendor/symfony/framework-bundle/KernelBrowser.php(171): Symfony\Component\HttpKernel\HttpKernelBrowser->doRequest()
      #17 vendor/symfony/browser-kit/AbstractBrowser.php(370): Symfony\Bundle\FrameworkBundle\KernelBrowser->doRequest()
      #18 vendor/symfony/browser-kit/AbstractBrowser.php(292): Symfony\Component\BrowserKit\AbstractBrowser->request()
      #19 vendor/friends-of-behat/mink-browserkit-driver/src/BrowserKitDriver.php(719): Symfony\Component\BrowserKit\AbstractBrowser->submit()
      #20 vendor/friends-of-behat/mink-browserkit-driver/src/BrowserKitDriver.php(494): Behat\Mink\Driver\BrowserKitDriver->submit()
      #21 vendor/friends-of-behat/mink/src/Element/NodeElement.php(153): Behat\Mink\Driver\BrowserKitDriver->click()
      #22 vendor/friends-of-behat/mink/src/Element/NodeElement.php(161): Behat\Mink\Element\NodeElement->click()
      #23 vendor/friends-of-behat/mink/src/Element/TraversableElement.php(115): Behat\Mink\Element\NodeElement->press()
      #24 tests/Behat/FeatureContext.php(89): Behat\Mink\Element\TraversableElement->pressButton()

@fancyweb
Copy link
Contributor

@that-guy-iain Can you please provide a minimal reproducer project?

@jderusse
Copy link
Member

Might be related to #45002

@that-guy-iain
Copy link
Contributor

@fancyweb so far no. I've tried to but I can't reproduce it so far in my new skeleton.

@willemverspyck
Copy link
Contributor

I'm having the same problem after upgrade to 6.0.3

@derrabus
Copy link
Member

We cannot fix a problem we cannot reproduce. Please either produce a reproducer as described here or a PR with a failing test case.

@that-guy-iain
Copy link
Contributor

I would be able to provide access to a private repo that has the issue. I just can't seem to reproduce it in a new product. So if that could be of help then someone can message me on the Symfony Slack under @icambridge and I can provide that.

@nicolas-grekas
Copy link
Member

Please check #45255 and tell us if it fixes the issue you're having.

nicolas-grekas added a commit that referenced this issue Jan 31, 2022
… parent class (filiplikavcan)

This PR was merged into the 4.4 branch.

Discussion
----------

[PropertyAccess] Fix handling of uninitialized property of parent class

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| Tickets  | Fix #45233
| New feature?  | no
| Deprecations? | no
| License       | MIT

[This fix](27d5edf#r795578649) introduced a new bug:

```php
class X
{
    public int $a;
}

class Y extends X
{
}

(new Y)->a;

// PropertyAccessor expects: Typed property Y::$a must not be accessed before initialization
// Actual exception message: Typed property X::$a must not be accessed before initialization
```

This prevents from throwing `AccessException` exception and it bubbles up and causes this exception after form submit: "Typed property X::$a must not be accessed before initialization" which would otherwise be handled by PropertyPathAccessor:

```php
        } catch (PropertyAccessException $e) {
            // ...

            return null;
        }
```

Commits
-------

5cd10b0 [PropertyAccess] Fix handling of uninitialized property of parent class
@that-guy-iain
Copy link
Contributor

@nicolas-grekas I'm assuming the line 439 in that PR is to be applied to 431 in 6.0.3?

@willemverspyck
Copy link
Contributor

Thanks @derrabus and @nicolas-grekas. This fix worked for me.

@that-guy-iain: Yes, it's applied to 430 and 431 in 6.0.3

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

9 participants