hi all,
i have one question around return function
for ex.
[code=php]<?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 is used two functions. one serve as getting values and the other one serve as setting values. Why we cannot use for this both getting values and setting together inside one function. such as below.
[code=php]<?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