This is a basic example of what I have:
class A {
function MyPrivateFunction() {
return "Something that should only be seen within Class A";
}
function A($y) {
$x = MyPrivateFunction(); // this is ok b/c it is inside of Class A
// Do something with $x and $y to get $z
return $z;
}
function foo($q) {
$x = MyPrivateFunction($q); //this is ok b/c it is inside of Class A
// more stuff here
return $foobar;
}
}
$c = new A("blah");
$foo = $c->foo(); // this is Ok b/c I don't care if it is private or not
$bar = $c->MyPrivateFunction(); // don't want this to be allowed as it is outside of Class A
What I want is to make it so that MyPrivateFunction can only be called from within A. It's been a while since I took Java, but I believe this is akin to a private function in Java. Is this possible in PHP4?
Some background....
We have something like 20 different databases all with different usernames and passwords for the PHP user. I'm trying to make my life easy, by creating a DB class which when called with the DB name, will establish a connection to the db with the correct username/password. One function in the class, figures out the prefered username and password for that db and returns it back to the constructor which uses it to make the connection. The only problem is I don't want the code to be able to display this info anywhere outside of the class. Maybe I'm going about this all wrong. If there is a better way to do this please let me know.
Thanks.