Closed
Description
Moved from symfony/symfony#24783 created by @enumag
Q | A |
---|---|
Bug report? | yes |
Feature request? | no |
BC Break report? | no |
RFC? | no |
Symfony version | 3.3 |
I was reading the documentation of Symfony/Serializer component. Here I found info about a new feature in Symfony 3.3, the allow_extra_attributes
option. However the example from documentation does not work. This should throw a Symfony\Component\Serializer\Exception\ExtraAttributesException
but it does not:
<?php declare(strict_types = 1);
require __DIR__ . '/vendor/autoload.php';
(new \Symfony\Component\Dotenv\Dotenv())->load(__DIR__.'/.env');
$kernel = new \App\Kernel('dev', true);
$kernel->boot();
$container = $kernel->getContainer();
$serializer = $container->get('serializer');
class Person
{
private $age;
private $name;
private $sportsman;
// Getters
public function getName()
{
return $this->name;
}
public function getAge()
{
return $this->age;
}
// Issers
public function isSportsman()
{
return $this->sportsman;
}
// Setters
public function setName($name)
{
$this->name = $name;
}
public function setAge($age)
{
$this->age = $age;
}
public function setSportsman($sportsman)
{
$this->sportsman = $sportsman;
}
}
$data = <<<EOF
<person>
<name>foo</name>
<age>99</age>
<city>Paris</city>
</person>
EOF;
$person = $serializer->deserialize($data, 'Person', 'xml', array(
'allow_extra_attributes' => false,
));
var_export($person);
cc @juliendidier ref #19958, #6975