class.user.php . में आपके पास एक है:
function __construct($DB_con)
{
$this->db = $DB_con;
}
और जब आप इसका उपयोग logout.php . में करते हैं :
$user = new USER();
आपको $DB_con . पास करना होगा __constructor . के लिए , या एक __constructor create बनाएं जिसका कोई तर्क नहीं है, और DB . को इनिशियलाइज़ करने के लिए एक और फ़ंक्शन जोड़ें :
function __construct()
{
}
public function initDB($DB_con)
{
$this->db = $DB_con;
}
और फिर आप इसे इस तरह इस्तेमाल कर सकते हैं:
$YourDB = whatever_get_DB();
$user = new USER();
// And when you need:
$user.initDB($YourDB);
या केवल इसके बिना:
$YourDB = whatever_get_DB();
$user = new USER($YourDB);