Why we generally use getter setters for doctrine2 classes to save and get data?
like below:
<?php
// src/Product.php
class Product
{
/**
* @var int
*/
protected $id;
/**
* @var string
*/
protected $name;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
}
If we make the the class properties public we can save the data without getter setters. Isn't it?
<?php
// src/Product.php
class Product
{
/**
* @var int
*/
public $id;
/**
* @var string
*/
public $name;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With