-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Open
Description
Symfony version(s) affected
7.3.2
Description
There seems to be an issue introduced by #61036.
When calling map with a FQDN as target the mapping fails because the constructor is called without any arguments. Prior to the change the constructor was not called at all because $ctorArguments
is empty.
The issue does not occur when property promotion is being used because:
if (!$parameter->isPromoted()) {
continue;
}
does not lead to the filling of $ctorArguments
being skipped.
How to reproduce
<?php
namespace App;
class Foo {
public string $bar;
public function __construct(string $bar) {
$this->bar = $bar;
}
}
<?php
namespace App\Controller;
use App\Foo;
use stdClass;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\ObjectMapper\ObjectMapperInterface;
#[AsCommand(name: 'test')]
class TestCommand extends Command
{
public function __construct(
private readonly ObjectMapperInterface $mapper,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$object = new stdClass();
$object->bar = 'bar';
$foo = $this->mapper->map($object, Foo::class);
return Command::SUCCESS;
}
}
Too few arguments to function App\Foo::__construct(), 0 passed in /var/www/html/vendor/symfony/object-mapper/ObjectMapper.php on line 159 and exactly 1 expected
Possible Solution
No response
Additional Context
No response