Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Serializer] Example from documentation does not work #24783

Copy link
Copy link
Closed
@enumag

Description

@enumag
Issue body actions
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, symfony/symfony-docs#6975

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.