[eluser]TheFuzzy0ne[/eluser]
It's a question of scope. $data is available within the confines of the function it's declared in, if you declare $data as a class variable, it's available to the whole class, and accessed via $this->data. $this->something means you want to access a variable that's in the global scope of the current object. $this won't work outside of an object.
Code:
class Example {
var $data = 'Class data';
function getData($from_class=FALSE)
{
$data = "Function data";
if ($from_class === TRUE)
{
return $this->data; # returns the class variable
}
else
{
return $data; # returns the function variable.
}
}
}
$example = new Example();
echo $example->getData() . "\n"; # Echoes "Function data"
echo $example->getData(TRUE) . "\n"; # Echoes "Class data"
The above code is
untested.
I hope this helps without causing more confusion.