hi all,
i have one question around return function
for ex.
<?php
class Employee
{
private $name;
// Getter
public function getName() {
return $this->name;
}
// Setter
public function setName($name){
$this->name = $name;
}
}
$azer=new Employee();
$azer->setName('sahib');
echo $azer->getName();
?>
why here we must declare two functions. one serve as getting values and the other one serve as setting values. why i cannot use for this both getting values and setting together inside one functions. such as below.
<?php
class Employee
{
private $name;
// Getter
// Setter
public function setName($name){
$this->name = $name;
return $this->name;
}
}
$azer=new Employee();
$azer->setName('sahib');
echo $azer->setName();
?>
can anyone help me if possible
thanks in advance