What does $variable->something mean?

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
hamish
Forum Newbie
Posts: 1
Joined: Mon Oct 09, 2006 1:19 pm

What does $variable->something mean?

Post by hamish »

Hello

I have been using PHP for a while, but I often end up reusing old code and rarely learning new stuff.

I have seen on a lot of code (included the PHPBB code) that in PHP code sometimes look like:

Code: Select all

$variable->something
or

Code: Select all

$handle = db_connect();
$pages_sql = 'select * from table';
$result = $handle->query($pages_sql);
or something very similar. I would like to start using this more in my code because I have been told about the benefits.

Can someone tell me:
(a) what does the -> do ?
(b) what is the concept called?
(c) can you give me a brief example?

Huge thanks
Hamish
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Welcome to the world of object oriented programming hamish! :)
It is a big bright world indeed.

-> is called the arrow operator fyi and it gets a property (aka attribute / data member / class variable) or method (aka operation / function member / class function) for use much like an array subscript ([]) does.
Post Reply