Say I have this code:
class cats {
function cats_suck() {
$this->cats = "monkeys";
}
}
$cats = new cats;
$cats->cats_suck();
echo $cats->cats; //Monkeys?
I would like to pass $cats to outside of my class, I would usually just return $cats then echo the function, but I have a lot of variables in my code.
You could add a getter:
so then:
Or you could store all privates in an array and add a magic method for getting:
so then:
Which sort of defeats the purpose of having privates, but ours not to question why.