php this selfの使い方と違い

593 ワード

このself自身
$thisはインスタンス化されたオブジェクトを指し、selfは現在のクラスを指します.
   
    

$db  = new Imooc\Database();
var_dump($db->where('id=1'));




Database      $this,         $this  Database          .

   self     
class Database
{
    private static $db;

    static function getInstance()
    {
        if (self::$db) {
            return self::$db;
        } else {
            self::$db = new self();
            return self::$db;
        }
    }
}

  Database    ,         (       ),  $this        $this->db   ,
self  Database      ,self()       Database      .