Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Integrating PHP with Databases Databases and PHP Working with Objects

Cris Davi
Cris Davi
1,425 Points

What exactly does -> do/ represent?

Can't understand...

2 Answers

Niki Molnar
Niki Molnar
25,698 Points

-> is called the object operator and is used in objects to access the methods and properties of that object. At its basic level, it gets or sets an object variable within a class or other object, e.g. an array. The object is always on the left hand side, before the ->

$foo->bar(); // Calls a function called bar() within the object $foo
$foo->bar = 'Jim';  // Accesses a property called bar in the object $foo and sets it to Jim
Ezra Siton
Ezra Siton
12,644 Points

The answer above.

In general : Its hard to 100% understand this issue without some OOP knowledge:

https://teamtreehouse.com/library/objectoriented-php-basics-2 https://teamtreehouse.com/library/objectoriented-php-basics-2/understanding-classes/accessing-methods

In other Programming languages you find the use of dot (.) instead of ->.(If you know the consept of dot maybe it will help you to understand this issue)

// javascript
Math.random();

https://stackoverflow.com/questions/14037290/what-does-this-mean-in-php-or

https://stackoverflow.com/questions/2588149/what-is-the-php-operator-called-and-how-do-you-say-it-when-reading-code-out

http://php.net/manual/en/language.oop5.basic.php