Page 1 of 1

Help with syntax

Posted: Wed Jan 18, 2012 5:07 pm
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!

Re: Help with syntax

Posted: Wed Jan 18, 2012 5:55 pm
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