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

Skip to content

PhpDumper tries to access undefined method Alias::isShared #33942

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
gquemener opened this issue Oct 10, 2019 · 4 comments
Closed

PhpDumper tries to access undefined method Alias::isShared #33942

gquemener opened this issue Oct 10, 2019 · 4 comments

Comments

@gquemener
Copy link
Contributor

gquemener commented Oct 10, 2019

Symfony version(s) affected: 4.2+

Description
PhpDumper tries to access unknown method isShared from class Symfony\Component\DependencyInjection\Alias.

Here's the exact PHP error:

Error: Call to undefined method Symfony\Component\DependencyInjection\Alias::isShared() 

/app/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:1892
/app/vendor/symfony/dependency-injection/Dumper/PhpDumper.php:184

How to reproduce

  1. Clone the https://github.com/prooph/service-bus-symfony-bundle repository
  2. Install the dependencies (this will install symfony/dependency-injection:4.3.*)
  3. Run the testsuite (./vendor/bin/phpunit)

I haven't been able (yet) to create a more minimalist environment, sorry about that!

Possible Solution
In PhpDumper::isSingleUsePrivateNode, apply the following patch:

- if ($edge->isLazy() || !$value->isShared()) {
+ if ($edge->isLazy() || ($value instanceof Definition && !$value->isShared())) {

Additional context
Further investigations are being led on prooph/service-bus-symfony-bundle#79

@nicolas-grekas
Copy link
Member

if ($edge->isLazy() || !$value instanceof Definition || !$value->isShared()) { should do it.
Tests still fail after the change, but I don't know why. At least the fatal error is gone.
Please submit a PR on 4.3 when you're ready.

@gquemener
Copy link
Contributor Author

gquemener commented Oct 11, 2019

if ($edge->isLazy() || !$value instanceof Definition || !$value->isShared()) { should do it.

Sure, however I'm not sure what I'm doing here. I've spent a few hours trying to understand the internal of the php dumper and wondering where was the bug.
Is it that we have an Alias instance as the node value (thus, the bug is on the bundle side), or is it that the isSingleUsePrivateNode method does not handle this case (thus, the bug is on the component side)?

What do you think?
By reading the docblocks, it seems that having an Alias as the node value is a valid use case (https://github.com/symfony/symfony/blob/v4.3.5/src/Symfony/Component/DependencyInjection/Compiler/ServiceReferenceGraphNode.php#L101-L105).

@gquemener
Copy link
Contributor Author

gquemener commented Oct 11, 2019

For information, the testsuite of the bundle passes with symfony/dependency-injection:4.1.12, symfony/http-kernel:4.1 and symfony/framework-bundle:4.1.

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Oct 11, 2019

if ($edge->isLazy() || !$value instanceof Definition || !$value->isShared()) { should do it.

this patch is clearly needed
dunno yet why the test fails then

@xabbuh xabbuh closed this as completed in 831b00f Oct 14, 2019
xabbuh added a commit that referenced this issue Oct 14, 2019
* 4.3:
  fix PHP 5.6 compatibility
  [Cache] fixed TagAwareAdapter returning invalid cache
  Add plus character `+` to legal mime subtype
  Make Symfony\Contracts\Service\Test\ServiceLocatorTest abstract
  bug #33942 [DI] Add extra type check to php dumper
  [Dotenv] search variable values in ENV first then env file
  [PropertyInfo] Respect property name case when guessing from public method name
  [VarDumper] fix resetting the "bold" state in CliDumper
  Missing argument in method_exists
  SCA: added missing break in a loop
xabbuh added a commit that referenced this issue Oct 14, 2019
* 4.4:
  fix PHP 5.6 compatibility
  [Cache] fixed TagAwareAdapter returning invalid cache
  Add plus character `+` to legal mime subtype
  Make Symfony\Contracts\Service\Test\ServiceLocatorTest abstract
  bug #33942 [DI] Add extra type check to php dumper
  [Dotenv] search variable values in ENV first then env file
  [PropertyInfo] Respect property name case when guessing from public method name
  [VarDumper] fix resetting the "bold" state in CliDumper
  Missing argument in method_exists
  SCA: added missing break in a loop
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