Closed
Description
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()
)