开发者

How to use the -> in PHP [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

What does this php construc开发者_如何学Ct 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.


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

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

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

More Info:

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


It's for classes.

See here:

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


-> operator access properties and methods of an object.

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


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" 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜