クラスのインスタンスをクラス内のプロパティに保存して、複数の初期化を無効にしました(意味があることを願っています)。
こんな風に見える:
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 ;)
}
}