OOP: class varibales question
| From: | Chris Carbaugh | Date: | Thu, 09 Nov 2000 19:59:31 +0000 |
| Subject: | OOP: class varibales question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-24544@lists.php.net to get a copy of this message | ||
I ran into a clash between class variables today. I entended a class,
and in the new class I created a variable with the same name that the
original class defined. This of course corrupted the data in the
varible(s).
Here's a sample:
class A {
var $data = "foo";
function dofoo(){
// do something with $data
}
}
class B extends A {
var $data = "bar";
function dobar(){
// do something with $data
}
}
Now class A expects it's $data not be messed with by outsiders.
Class be (the outsider) doesn't know class A uses $data, and changes
it.
Or class B calls a method defined in A which uses A's definition of
$data, thereby corrupting B's definition of $data.
Am I making sense here?
I have only read a little about OPP in languages like C++, but I think
this is the point of public/private variables?
I don't think php supports privates vars, so is there any way to avoid
this situation?
Thanks,
Chris