Can someone explain ($this->varname) to me..

Can someone explain ($this->varname) to me..

am 31.08.2007 19:44:29 von laptopia

How and what does this mean in php: ($this->varname)

I can't seem to find this by searching Google, because the "->" are
removed from my search query.

Cheers,
Igor Terzic
www.stikimedia.com

Re: Can someone explain ($this->varname) to me..

am 31.08.2007 19:52:24 von 4sak3n 0ne

On Aug 31, 10:44 am, stiki wrote:
> How and what does this mean in php: ($this->varname)
>
> I can't seem to find this by searching Google, because the "->" are
> removed from my search query.
>
> Cheers,
> Igor Terzicwww.stikimedia.com

-> is used when referring to a classes inner workings. $this is a
special variable used within a class to refer to itself.

Example:
----------------------------------------
class Example{
var $classVariable = "Something";

function testFunction(){
echo "I'm just a simple function.";
}

function show(){
$this->testFunction();
}
}

$c = new Example;
$c->testFunction(); // Returns I'm just a simple function.
$c->show(); // Returns I'm just a simple function.
echo $c->classVariable; // Returns Something
------------------------------------------

Hope that clears thing up for you.

Re: Can someone explain ($this->varname) to me..

am 31.08.2007 19:53:49 von zeldorblat

On Aug 31, 1:44 pm, stiki wrote:
> How and what does this mean in php: ($this->varname)
>
> I can't seem to find this by searching Google, because the "->" are
> removed from my search query.
>
> Cheers,
> Igor Terzicwww.stikimedia.com

Read this:

Re: Can someone explain ($this->varname) to me..

am 01.09.2007 05:22:39 von luiheidsgoeroe

On Fri, 31 Aug 2007 19:52:24 +0200, 4sak3n 0ne <4sak3n0ne@gmail.com> wrote:

> On Aug 31, 10:44 am, stiki wrote:
>> How and what does this mean in php: ($this->varname)
>>
>> I can't seem to find this by searching Google, because the "->" are
>> removed from my search query.
>>
>> Cheers,
>> Igor Terzicwww.stikimedia.com
>
> -> is used when referring to a classes inner workings. $this is a
> special variable used within a class to refer to itself.

To be more precise: it refers to the containing object (instance of a
class). A reference to a class itself would normally be something like
self::$varname.
--
Rik Wasmus

My new ISP's newsserver sucks. Anyone recommend a good one? Paying for
quality is certainly an option.

Re: Can someone explain ($this->varname) to me..

am 03.09.2007 17:52:31 von Tony Marston

"stiki" wrote in message
news:1188582269.180135.221550@q4g2000prc.googlegroups.com...
> How and what does this mean in php: ($this->varname)
>
> I can't seem to find this by searching Google, because the "->" are
> removed from my search query.
>
> Cheers,
> Igor Terzic
> www.stikimedia.com
>

$this->varname refers to a class variable (property) which is available to
any function (method) within that class. This is not to be confused with
$varame which refers to a variable whose scope is limited to the current
method.

$this->function() refers to another function (method) within the same class,
as opposed to function() without $this->) which refers to a non-class method
which exists in global scope.

Basically $this-> is used within a class method to refer to something else
which exists within the same class.

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org