Why Directly Accesing property is not recommended in OOPs PHP?

Posted by Parth on Stack Overflow See other posts from Stack Overflow or by Parth
Published on 2010-04-22T05:33:05Z Indexed on 2010/04/22 5:53 UTC
Read the original article Hit count: 309

Filed under:
|

If I have a class "person" with a property $name and its getter(get_name()) and setter(set_name()) methods, then after instantiating the objects and setting the property i.e.

$paddy = new person();

$paddy->set_name("Padyster Dave");

echo "Paddy's full name: ".$paddy->name; //WHY THIS IS NOT RECOMMENDED...

In the above code $paddy->name;WHY THIS IS NOT RECOMMENDED?

© Stack Overflow or respective owner

Related posts about php

Related posts about oop