I am currently developing a PHP application (v5.3.5 if it matters) and stumbled upon this question that I cannot seem to get a clear answer to while searching the internet.
So let's say I have a class Body
that has two properties: m_bAlive
and m_oHead
. Head is an instance of a class that has setters and getters for it's properties (see example code). Should this object be public or private/protected as you'd normally declare it unless something else is necessary?
<?php
class Body {
private $m_bAlive;
private /*public*/ $m_oHead;
//...
//Getters and Setters here
}
class Head {
private $m_bIsBald;
//...
//Getters and Setters here
}
By habit, I'd want to make $m_oHead
private
, but it feels as if it'd be overly complicated (and possibly slow?) to write $oBody->getHead()->getIsBald()
. Maybe it just looks unusual to me because I don't come across this situation often, but I want to make sure.