C. MARTIN
C. MARTIN

Reputation: 61

Symfony 6 php 8 Entity Form

I'm trying to create a form with Symfony 6 (without database behind).

I create an Entity like this :

<?php

namespace App\Entity;

class MyObject
{
    private string $name;

    public function getName(): ?string
    {
        return $this->$name;
    }

    public function setName($name): self
    {
        $this->$name = $name;

        return $this;
    }
}

?>

I created the MyObjectFormType with symfony console make:entity command.

After that when I tried to show the form into my twig page, I've got an error Warning: Undefined variable $name. I saw that in older version of php (and symfony) this annotation was used:

/**
 * @Var
 */

Does it exist on php 8 (by attributes)?

Upvotes: 0

Views: 143

Answers (1)

S.Toullec
S.Toullec

Reputation: 51

You have an error, it's not:

$this->$name

but:

$this->name

Upvotes: 1

Related Questions