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: 222

Filed under:
|

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

Related posts about php

Related posts about object-oriented