What does $this actually mean> Codeigniter

后端 未结 6 849
攒了一身酷
攒了一身酷 2020-12-09 11:25

Silly question I know,

From all the tutorials they do not explain why they use $this.

Is $this like an object from a base class in Codeigniter?

Any e

6条回答
  •  离开以前
    2020-12-09 12:00

    $this isn't something from CodeIgniter, but from PHP. $this refers to the current object.

    Whenever you create an instance like this:

    $something = new SomeClass();
    

    Then $this refers to the instance that is created from SomeClass, in this case $something. Whenever you are in the class itself, you can use $this to refer to this instance. So:

    class SomeClass {
    
      public $stuff = 'Some stuff';
    
      public function doStuff()
      {
        $this->stuff;
      }
    
    }
    

提交回复
热议问题