What does the variable $this mean in PHP?

前端 未结 10 1777

I see the variable $this in PHP all the time and I have no idea what it\'s used for. I\'ve never personally used it.

Can someone tell me how the variab

10条回答
  •  日久生厌
    2020-11-22 05:43

    $this is a special variable and it refers to the same object ie. itself.

    it actually refer instance of current class

    here is an example which will clear the above statement

    price = $par;
      }
    
      function getPrice(){
         echo $this->price ."
    "; } function setTitle($par){ $this->title = $par; } function getTitle(){ echo $this->title ."
    "; } } ?>

提交回复
热议问题