I was talking about attributes rather than common variables.
It is my understanding that, as you stated, they are available to every
method of the class. I assume this is the case regardless of what method
assigns the value to that attribute?
For example:
class MyClass{
var $myvar;
function one (){
$this->myvar = "foobar";
}
function two(){
echo $this->myvar;
}
function three(){
$temp = "this is a ";
return $temp . $this->myvar;
}
}
What I am finding as that in some instances two() is sending nothing to the
browser, even if one() has been called first. If I use myvar in another
method, in this example three(), between the calls to one() and two(), then
even though three() contains no code to alter the value of myvar, the
subsequent call to two() returns nothing.
I gather I have just done something wrong in my code and that?
Hamilton
"Antti Lahtonen" <an******@verso.st.jyu.fi> wrote in message
news:bi**********@mordred.cc.jyu.fi...
Spidah <ha******@eyehug.co.nz> kirjoitti:
What is happening is that when functions in my class go to access
variables they are returning nothing even though they have had values assigned..
You must have something wrong in your code. :) An example would have
helped a lot.
What do you mean with a variable - a common variable or an attribute?
Attributes are available in all functions (methods) of the class, but
common variables only in the functions they are declared in.
class foo {
var $bar = 'foobar'; // attribute
function example() {
print $this->bar; // prints foobar
$variable = 'cheese'; // variable
}
function example2() {
print $variable; // prints nothing
}
}
--
Antti Lahtonen
http://www.iki.fi/andu/