Page 1 of 1
What does $this mean?
Posted: Tue Oct 25, 2005 8:11 pm
by Sequalit
What does
mean in PHP????
Posted: Tue Oct 25, 2005 8:13 pm
by feyd
it's used inside objects, it is a reference to the current instance of the object.. it's used to access other information in the object, normally instance sensitive.. such as variables set during operation of the object that vary between creations..
Posted: Tue Oct 25, 2005 8:14 pm
by sweatje
$this is the current instance of a class. $this->var allows you to set or read attributes of the instance. $this->method() allows you to run methods of the class.
Posted: Tue Oct 25, 2005 8:18 pm
by Sequalit
thanks for the fast response, i believe i understand it now =D

Posted: Tue Oct 25, 2005 8:48 pm
by John Cartwright
Code: Select all
class foobar {
function foobar() {
$this->fooVar = 'fooVar!!!!';
}
function getFooVar() {
return $this->fooVar;
}
}
$foo &= foobar();
echo $foo->getFooVar();
just in case you didn't get it

Posted: Wed Oct 26, 2005 1:06 am
by Jenk
This is a thinly related subject, but are self::method() and $this->method(); the same, with the exception of the SRO being a static call? Or would self::method() be the same as calling className::method() from outside of the class?