Page 1 of 1

Can anybody explain the usage of "->"?

Posted: Sat Oct 16, 2010 7:41 pm
by rodsem
Maybe this is just a simple thing, but I haven't been able to search for it 'cause of the syntax, even if I enclose it like "->", search engines and forum search engines seem to nos recognize it.

I just need to know what it the usage of "->" in PHP and if it has a name so I can research more about it...

Re: Can anybody explain the usage of "->"?

Posted: Sat Oct 16, 2010 8:06 pm
by Jonah Bron
That is an object notation. Here's an example:

Code: Select all

class Person {
    public $height;
    public $age;
    function setAge($age) {
        $this->age = $age;
    }
}

$instance = new Person();

$instance->setAge(20);

echo $instance->age; // outputs "20"
$instance->height = '5-4';
echo $instance->height; // outputs "5-4"
$this is a special variable referring to the current object instance. For more information on objects, classes, and object oriented programming, here are some links.

http://php.net/manual/en/language.oop5.php
http://www.google.com/#q=php+object+ori ... rogramming

Re: Can anybody explain the usage of "->"?

Posted: Sat Oct 16, 2010 8:25 pm
by rodsem
Great! Thank you Jonah. Now I know a little bit more but the most important is that now I know how to look for it.