Page 1 of 1

What does $variable->something mean?

Posted: Mon Oct 09, 2006 1:24 pm
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

Posted: Mon Oct 09, 2006 1:28 pm
by volka

Posted: Mon Oct 09, 2006 5:07 pm
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.