Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal Error: Class 'SELF' not found

Tags:

php

class

I have the following relevant code:

try {
    self::$db = new PDO($dsn, self::USER, SELF::PASS); //Connect to the database, and store the pdo object.
    self::$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
    throw new Exception("There have been an error in the connection: ". $e->getMessage());
}

When executing the static function this code is in, I get the following error:

Fatal error: Class 'SELF' not found in P:ath/to/script.php on line 107

I have no idea what might cause this, can anyone please enlighten me?

Thanks in advance.

like image 732
Madara's Ghost Avatar asked Nov 29 '22 03:11

Madara's Ghost


2 Answers

Use self::PASS instead of SELF::PASS

like image 195
Dor Shemer Avatar answered Dec 05 '22 23:12

Dor Shemer


First line self and SELF isn't the same thing...

self::$db = new PDO($dsn, self::USER, self::PASS);
like image 23
Juicy Scripter Avatar answered Dec 06 '22 00:12

Juicy Scripter