Can anybody explain the usage of "->"?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rodsem
Forum Newbie
Posts: 5
Joined: Mon May 16, 2005 1:21 am

Can anybody explain the usage of "->"?

Post 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...
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

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

Post 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
rodsem
Forum Newbie
Posts: 5
Joined: Mon May 16, 2005 1:21 am

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

Post 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.
Post Reply