Why setter method when getter method enough in PHP OOP
Posted
by
phphunger
on Programmers
See other posts from Programmers
or by phphunger
Published on 2012-09-17T12:12:59Z
Indexed on
2012/09/17
15:52 UTC
Read the original article
Hit count: 259
php
|object-oriented
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();
?>
© Programmers or respective owner