04-20-2008, 06:25 PM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Apr 2008
Posts: 12
Thanks: 7
|
How do i lock a variable in a class
How do i lock a variable in a class so that i can read it but not change it in an instance, without using return.
Class EX:
PHP Code:
class MyClass
{
public $var;
public function ChangeVar(){
$this->var = rand(1,20);
}
}
With this i can still change the variable inside the class though.
PHP Code:
$class = new MyClass;
$class->ChangeVar();
//But i can also do this, though i don't want to
$class->var = 50;
Is it at all possible to do without using return?
EDIT:
Using PHP5 btw.
|
|
|
|