Why setter method when getter method enough in PHP OOP
- by phphunger
I am practicing OOP with PHP, and I am struck at setter and getter methods.
I can directly access the class properties and methods with getter method then what's the use of setter method?
See my example.
<?php
class MyClass{
public $classVar = "Its a class variable";
public function Getter(){
return $this -> classVar;
}
}
$obj = new MyClass;
echo $obj -> Getter();
?>