8000 Cannot access parent:: when current class scope has no parent · Issue #41133 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Cannot access parent:: when current class scope has no parent #41133

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
Androbin opened this issue May 7, 2021 · 3 comments
Closed

Cannot access parent:: when current class scope has no parent #41133

Androbin opened this issue May 7, 2021 · 3 comments

Comments

@Androbin
Copy link
Androbin commented May 7, 2021

Symfony version(s) affected: 4.4

Description
If $p->getDefaultValueConstantName() starts with parent::, defined interprets it relative to the wrong base class.

How to reproduce
Minimal reproducing test project, only need to run composer install

Possible Solution
See #40774

Additional context

Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception

  [RuntimeException]
  An error occurred when executing the "'cache:clear --no-warmup'" command:

  PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Cannot access parent:: when current class scope has no parent in ./vendor/symfony/symfony/src/Symfony/Component/Config/Resource/ReflectionClassResource.php:167
  Stack trace:
  #0 ./vendor/symfony/symfony/src/Symfony/Component/Config/Resource/ReflectionClassResource.php(167): defined()
  #1 ./vendor/symfony/symfony/src/Symfony/Component/Config/Resource/ReflectionClassResource.php(117): Symfony\Component\Config\Resource\ReflectionClassResource->generateSignature()
  #2 ./vendor/symfony/symfony/src/Symfony/Component/Config/Resource/ReflectionClassResource.php(66): Symfony\Component\Config\Resource\ReflectionClassResource->computeHash()
  #3 [internal function]: Symfony\Component\Config\Resource\ReflectionClassResource->serialize()
  #4 ./vendor/symfony/s in ./vendor/symfony/symfony/src/Symfony/Component/Config/Resource/ReflectionClassResource.php on line 167
@n0rbyt3
Copy link
Contributor
n0rbyt3 commented May 14, 2021

This snippet is easier to understand the issue:

namespace AnotherLib {
    class Message {
        const NOTIFY_REGULAR = "REGULAR";
    }

    class StructuredMessage extends Message {
        public function __construct($notificationType = parent::NOTIFY_REGULAR) {
        }
    }
}

namespace App {
   class MyMessage extends \AnotherLib\StructuredMessage {
   }
}

Edit: StructedMessage extends Message

@xabbuh
Copy link
Member
xabbuh commented May 17, 2021

@n0rbyt3 I am not sure how this is related to Symfony. This seems to be invalid PHP code per se: https://3v4l.org/hB7Rr

@n0rbyt3
Copy link
Contributor
n0rbyt3 commented May 17, 2021

@xabbuh Sorry, I missed StructuredMessage extends Message (which is equal to the code of the library). This is valid code: https://3v4l.org/m9Por

nicolas-grekas added a commit that referenced this issue Jun 23, 2021
…rent class (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[Config] fix tracking default values that reference the parent class

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

Commits
-------

978747e [Config] fix tracking default values that reference the parent class
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

5 participants
0