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

Skip to content

[DI] Syntax error on dumped service using expression-language #29403

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
chalasr opened this issue Dec 1, 2018 · 0 comments
Closed

[DI] Syntax error on dumped service using expression-language #29403

chalasr opened this issue Dec 1, 2018 · 0 comments

Comments

@chalasr
Copy link
Member

chalasr commented Dec 1, 2018

Symfony version(s) affected: 4.2 only (stable and dev)

Description

On a fresh symfony/skeleton:^4.2 installation given the following services:

services:
    App\InlineDepProvider: ~

    App\Consumer:
        arguments:
            - '@=service("App\\InlineDepProvider").getInlineDep()'
            - 'somestring'

    App\FooCommand:
        arguments:
            - '@App\Consumer'
        tags: ['console.command']

And the corresponding classes:

namespace App;

class InlineDep
{    
}

class InlineDepProvider
{
    public function getInlineDep(): InlineDep
    {
        return new InlineDep();
    }
}

class Consumer
{
    public function __construct(InlineDep $inlineDep, string $somestring)
    {
    }
}

class FooCommand extends Command
{
    public function __construct(Consumer $consumer)
    {
        parent::__construct('foo');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
    }
}

And running bin/console foo:

[Symfony\Component\Debug\Exception\FatalThrowableError]
syntax error, unexpected '->' (T_OBJECT_OPERATOR), expecting ',' or ')'

Exception trace:
 () at /Volumes/HD/Sites/tests/di-42-inline-bug/var/cache/dev/ContainerUpgmmiP/getFooCommandService.php:13

Dumped getFooCommandService.php:

return $this->services['console.command.public_alias.App\FooCommand'] = new \App\FooCommand(new \App\Consumer(new \App\InlineDepProvider()->getInlineDep(), 'somestring'));

How to reproduce
Checkout https://github.com/chalasr/di-42-inline-bug, run composer install and bin/console.

Project created via

  • composer create-project symfony/skeleton:^4.2 di-42-inline-bug
  • composer req expressionlanguage

Possible Solution
Dumped getFooCommandService.php should look like:

return $this->services['console.command.public_alias.App\FooCommand'] = new \App\FooCommand(new \App\Consumer((new \App\InlineDepProvider())->getInlineDep(), 'somestring'));

(adding parenthesis around new \App\InlineDepProvider() )

nicolas-grekas added a commit that referenced this issue Dec 2, 2018
…services (chalasr)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Fix dumping expressions accessing single-use private services

| Q             | A
| ------------- | ---
| Branch?       | 4.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29403
| License       | MIT
| Doc PR        | n/a

Introduced in #27268, see fixed ticket

Commits
-------

d1e84aa [DI] Fix dumping expressions accessing single-use private services
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

3 participants