站內搜尋

Monday, July 22, 2013

[PHP][OOP] $this的用法

存取"當前"物件的屬性,例如:
class My_cls{  public $my_str;  public function my_fun(){   return $this -> my_str;  } } $my_obj = new My_cls(); $my_obj -> my_str = 'asdf'; echo $my_obj -> my_fun();  //印出結果為asdf

No comments:

Post a Comment