Home > Software engineering >  Symfony 6 php 8 Entity Form
Symfony 6 php 8 Entity Form

Time:06-28

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)?

CodePudding user response:

You have an error, it's not:

$this->$name

but:

$this->name
  • Related