Page 1 of 1

What does "->" signify in php

Posted: Fri Nov 07, 2008 4:59 pm
by swraman
Some code Im working with uses the line

pg_query($this->link, $query)

What does the $this->link signify?

Thanks

Re: What does "->" signify in php

Posted: Fri Nov 07, 2008 5:16 pm
by requinix
-> is for accessing variables and functions from an object.
$this is a special variable that refers to the class that the code is located in.

As usual, the manual is great for answering your PHP-related questions.

Code: Select all

class A {
    function x() { echo get_class($this); }
}
 
class B {
    var $b = 123;
}
 
$a = new A;
$a->x(); // prints "A"
$b = new B;
echo $b->b; // prints "123"

Re: What does "->" signify in php

Posted: Fri Nov 07, 2008 9:22 pm
by swraman
OK thank you.

I think I understand what $this does, but I am not sure...

What does $this do? What is the difernce between $this->$whatever and just saing $watever?

thank

Re: What does "->" signify in php

Posted: Sat Nov 08, 2008 1:38 am
by requinix
swraman wrote:What is the difernce between $this->$whatever and just saing $watever?
$this->whatever is the "whatever" variable that's part of the current class. $whatever is just a variable in a function.