我已经将一个类的实例存储在一个类内的一个属性中以进行 void 多重初始化,(希望这是有道理的)。
看起来像这样:
class baseClass
{
public $db;
public function __construct()
{
$this->db = new dbClass(); // this class is just a query class
}
}
class page extends baseClass {
public function __construct()
{
parent::__construct();
}
public function index()
{
// this works very fine and return result what i want //
$user = $this->db->query('blah blah');
// my problem is when i use the same property ($this->db) which
//contains the dbClass()
$mesg = $this->db->query('blah blah');
// the result of both query merge together
// i think i figured out whats the problem here but i dont know what to do
// i think i need to reset or the destroy the instance of $this->db
// and back it to null values
// or when i put print_r($this->db) after my first query (the $users )
// it display the previous property i set (ofcourse)
// what i want is.. every time i use the $this->db, i want
// it like the first time i use it, or fresh.
// is there any way ?
// thanks for the help experts ;)
}
}