0
I’m having a problem I can’t reference a method that’s within the class:
Follow the code:
define("LOGIN","root");
define("PWD","");
//define("DB", "pj_fatec");
define("DB", "virtual");
define("SERVER","localhost");
class Conexao {
public static $conn;
public function open() {
self::$conn = new mysqli(SERVER, LOGIN, PWD, DB);
// Check connection
if (self::$conn->connect_error) {
die("Connection failed: " . self::$conn->connect_error);
}
}
static function getconexao(){
if(self::$conn){
return self::$conn;
}else{
$this->open();
return self::$conn;
}
}
}
It’s probably because you’re referencing an object
$this
within a static function, which can be directly accessed by the class.– Laerte
the problem is to use the open() method without this and with the problems.
– Igor Henrique
In this case you have to change the function
open()
to Static and callself::open()
in the second function.– Laerte