1

Possible Duplicate:
What does this php construct mean: $html->redirect(“URL”)?

Hi, I've been looking for what this operator "->" does, but I can't seem to find a reference to it, only people using it in come and I can't make out what its doing, an explanation would be appreciated.

Community
  • 1
  • 1
Mankind1023
  • 7,198
  • 16
  • 56
  • 86
  • *(reference)* See [`T_OBJECT_OPERATOR` in List of Parser Tokens](http://php.net/manual/en/tokens.php) – Gordon Aug 06 '10 at 14:41

4 Answers4

3

The -> is used with object methods/properties, example:

class foo{
  function bar(){
    echo 'Hello World';
  }
}

$obj = new foo;
$obj->bar(); // Hello World

More Info:

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
2

It's for classes.

See here:

http://de.php.net/manual/en/language.oop5.basic.php

Dinah
  • 52,922
  • 30
  • 133
  • 149
JochenJung
  • 7,183
  • 12
  • 64
  • 113
2

-> operator access properties and methods of an object.

Probably you should read PHP OOP introduction: http://php.net/manual/en/language.oop5.php

ggarber
  • 8,300
  • 5
  • 27
  • 32
1

Expanding on sarfraz's answer to demonstrate how to access properties:

class foo{
  public $value = "test"; 
  function bar(){
     //// code
  }
}

$obj = new foo;
$obj->bar();
echo $obj->value;     //displays "test" 
Chris
  • 11,780
  • 13
  • 48
  • 70
  • would this be the same as saying bar($value)? – Mankind1023 Aug 06 '10 at 14:55
  • No... bar($value) is not really useful without having $object=new foo(); and calling $obj-bar() which is a method, whereas $value is a member/field of the class. – Chris Aug 06 '10 at 23:36