What does -> do?

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
TheBrandon
Forum Commoner
Posts: 87
Joined: Tue May 20, 2008 8:55 am

What does -> do?

Post by TheBrandon »

I've been looking for this answer online for a while now. I'm sure it's simple, but what does "->" do?

Context is like this:

Code: Select all

if($session->logged_in){
}else{}
It seems to be saying "is" but why not use "=" or "=="?

Is there a difference between = or == and -> ? What is the difference?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: What does -> do?

Post by Mark Baker »

TheBrandon wrote:I've been looking for this answer online for a while now. I'm sure it's simple, but what does "->" do?
It's OOP syntax; and it doesn't mean what you think it does.

Code: Select all

$session->logged_in
$session is an instantiated object (you don't show us enough code for us to identify what class it might be), and this syntax returns the "logged_in" attribute of that object.
The "logged_in" attribute is probably a boolean in this case
TheBrandon
Forum Commoner
Posts: 87
Joined: Tue May 20, 2008 8:55 am

Re: What does -> do?

Post by TheBrandon »

Can you recommend somewhere to learn about this syntax further?

It definitely interests me.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: What does -> do?

Post by Mark Baker »

TheBrandon wrote:Can you recommend somewhere to learn about this syntax further?

It definitely interests me.
The PHP manual is always useful: but probably only if you're already familiar with the principles of OOP, and want to know how they can be applied (and what limitations apply) in PHP.

I'm not sure where the best place to learn OOP principles would be, but I'm sure other people can help give you a few leads on that. It is worth learning if you want to do serious coding work.
JasonDFR
Forum Commoner
Posts: 40
Joined: Wed Jan 07, 2009 3:51 am

Re: What does -> do?

Post by JasonDFR »

What limitations apply?
Post Reply