Help with syntax

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
svoltmer
Forum Newbie
Posts: 1
Joined: Wed Jan 18, 2012 5:04 pm

Help with syntax

Post by svoltmer »

I am just learning php 5 and mysql and am running across statements with "->" in them. What does it mean and when do you use it? Sorry for my ignorance, but I have googled it and there is NOTHING. Thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Help with syntax

Post by Christopher »

-> provides access to a property or method of an instantiated object. So:

Code: Select all

class Foo {
     public $bar = 5;

     public function baz() {
          return "Hello";
     }
}

$foo = new Foo();
echo $foo->bar;     // outputs '5'
echo $foo->baz();    // outputs 'Hello'
I recommend you read this page in the manual (and then the whole Classes and Objects section):

http://www.php.net/manual/en/language.oop5.basic.php
(#10850)
Post Reply