2

I'm learning Symfony2 now and in every tutorial I read, there are protected variables, like:

/**
 * @ORM\Column(type="decimal", scale=2)
 */
protected $price;

/**
  * @ORM\Column(type="text")
  */
protected $description;

What I got from the command line generator is:

 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var integer
 *
 * @ORM\Column(name="game", type="integer")
 */
private $game;

Can someone explain why this is happening?

René Höhle
  • 26,716
  • 22
  • 73
  • 82
Tomek Buszewski
  • 7,659
  • 14
  • 67
  • 112

1 Answers1

6

Protected is not public !

private scope when you want your variable to be visible in its own class only.

protected scope when you want to make your variable visible in all classes that extend current class including the parent class.

There isn't a big difference in this exemple. The code from the SF documentation is more open to inheritance, that's all. Both are working.

(source: What is the difference between public, private, and protected?)

Community
  • 1
  • 1
Julien Lafont
  • 7,869
  • 2
  • 32
  • 52