Monday 30 May 2016

How to acess Private function of another class in PHP

I have a dbHandeller.php file . as follow



class dbHandeler {

var $conn;

public function __construct(){

$this->initiatedb();

}

private function initiatedb(){

//Details of the Databse
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "xxxxxx";

// Create connection
$this->conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$this->conn) {
die("Connection failed: " . mysqli_connect_error());
}else
return $this->conn;

}

private function sql_query($query){

}

}


Then I have donation.php and it extends the DB class



function __autoload($class_name) {
include $class_name . '.php';
}

class donation extends dbHandeler{


public function __construct(){

$dbObj = new dbHandeler();
$dbObj->initiatedb();
}

public function putDonation(){
var_dump($_POST);

}

public function getDonation(){


}
}


When I try to access the donation class I am getting following error




Fatal error: Call to private method dbHandeler::initiatedb() from context 'donation' in C:\xampp\htdocs\templeform\api\donation.php on line 13

error

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...