Thursday, July 12, 2018

php - private function __construct() not working when class called on another page

im using the following type of class...



class datas{


protected $req ;
protected $db ;


private function __construct()
{
$this->db = new Database('localhost', 'user', 'pass', 'db');
$this->db->connect();
}

public function prnt()
{
echo "afafa6e5f1ga56d18a1ge";
}
}


when i try and access the class like



$y = new datas();
$y->prnt();



Call to protected data::__construct() from invalid context




when i turn it to public, it works. is there any way to make the constructor private and still have the method of call like i have. and i was thinking which one is more secure .



any insight is appreciated guys.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...