Re: private variable in object ??
| From: | Richard Lynch | Date: | Fri, 29 Dec 2000 22:46:28 +0000 |
| Subject: | Re: private variable in object ?? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-32237@lists.php.net to get a copy of this message | ||
> hi, I'm used programming OO in java.
> the variable in a class could be private. only instance of te same classe
> can directly access those variable. all other have to use functions
> like
> name = someObject.getName()
>
> I'd like to know if php uses (or is able to use) this structure because in
> this way the programmer got more control over all the things that happens
in
> a object.
Not at this time.
You can "fake it" by writing something not unlike this:
function private_foo($set = ''){
static $foo;
if (isset($set)){
$foo = $set;
}
return $foo;
}
class bar{
function bar(){
private_foo();
}
function set_bar($new_value){
private_foo($new_value);
}
}
Now, bar() essentially behaves like a private $bar variable.
Disclaimer: I don't use PHP OO.