Nerede bir PHP sınıfı veya PHP yöntemi self
ve $this->
arasındaki fark nedir?
Örnek:
Geçenlerde bu kodu gördüm.
public static function getInstance() {
if (!self::$instance) {
self::$instance = new PDO("mysql:host='localhost';dbname='animals'", 'username', 'password');;
self::$instance-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
return self::$instance;
}
Ama ben $this->
, bir sınıfın geçerli örneği (nesne) (aynı zamanda yanlış olabilir) ifade ettiğini hatırlıyorum. Ancak, ne fark eder?