Page 1 of 1

What does -> do?

Posted: Fri Mar 13, 2009 12:30 pm
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?

Re: What does -> do?

Posted: Fri Mar 13, 2009 1:05 pm
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

Re: What does -> do?

Posted: Fri Mar 13, 2009 2:48 pm
by TheBrandon
Can you recommend somewhere to learn about this syntax further?

It definitely interests me.

Re: What does -> do?

Posted: Fri Mar 13, 2009 4:17 pm
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.

Re: What does -> do?

Posted: Fri Mar 13, 2009 4:38 pm
by JasonDFR
What limitations apply?