Hi all,
Just wondering if someone might be able to help me out with 'the right way' to do PHP OO stuff. I like to do most of my PHP coding in an OO fashion, but sometimes the 'kludge' nature of PHP4's OO gets on my nerves, i.e. not having official namespaces for private/protected attributes and methods etc.
I have one part of me saying "ok, this is OO, so you should do it this way", but another part says "er, but this isn't proper OO, so don't worry about it".
Anyway, here are some examples of my confusion:
Ok. Good OO practice (indeed, many modules in the PEAR distribution exhibit this) dictates that really ALL attributes of a class should be private and that you should always use accessor methods (getters and setters) to deal with these attributes. Well this is fine, but sometimes you have 'private private' attributes, lol. You know, they are only intended for use within the class, and probably shouldn't even have accessors. For example, a person class - is this the best way:
var $age;
var $name;
var $_secrets;
function setAge() {...}
function getAge() {...}
function setName() {...}
function getName() {...}
age and name are "private" (with the _ typo tip), BUT they have accessors. Where as secrets is "private", but DOESN'T have accessors. Is that good practice? Or just dumb? 😃
Also, is there a 'nice' way to do "implementing" of a class? i.e. you have classes that are not immediately subclasses of a particular class, but they can "implement" the methods of that class? Maybe I'm hoping for too much out of PHP4 and should use Java... but I really like PHP... and Java seems bloated to me. 🙂
Any suggestions?