Hello,
Hopefully this explains what you need to know...
============
Setting a variable in a Class:
Class Example {
var $var1;
var $var2;
...
Setting variables is optional. You can simply set Class-global variables within your methods and be just fine. Declaring them beforehand is just proper etiquette in PHP as it is not strongly typed and does not require variable decalarations to be made before a value is assigned to one.
============
Giving a Class variable (property) a value:
Class Example {
var $var1;
var $var2;
function Example() {
//static value assigned in the constructor
$this->var1 = "somevalue";
$this->var2 = "someothervalue";
} //end Example()
...
The "$this->" pointer is being used so that no matter what name is given to a given instance of your Class, "$this->" will always refer to the "this" Class. If you used $example->var1, then each instance of your class would have to be named $example for the code to work correctly. It is the "$this->" pointer that makes a variables scope global within the Class and available to all of the methods therein. You can make method-level variables by creating simple variables such as $var3 within a given method. Such variables cannot be accessed outside that method.
============
Setting a Class property value dynamically and accessing that value through the instance
Class Example {
var $var1;
var $var2;
var $var3;
function Example() {
$this->var1 = "somevalue";
$this->var2 = "someothervalue";
} //end Example()
function _setVar3($value) {
$this->var3 = $value;
} //end setVar3()
function returnVar3() {
return $this->var3;
} //end returnVar3()
} //end Example Class
$examp = New Example;
$examp->setVar3("refvalue");
$var = $examp->returnVar3();
Here you can see that $var3's value is set with the setVar3() method. The value is passed by reference as an argument via $examp->setVar3("refvalue"). Then we return the value using the returnVar3() method. Typically, setVar3() will do some error handling, formatting, etc. of the data. Using the line $var = $examp->returnVar3() we place the returned value of $var3 into a variable called $var. If we echoed $var we would see "refvalue".
Hope that covers it...