I've two classes which extend another class.
But when the second object is instantiated gets the definitions of the first.
Object B gets the definitions of the object A
Class A
class a extends Connection{
public function __construct() { parent::__construct("TOKENS");}
public function helloA(){
echo "A";
}
}
Class B
class B extends Connection{
public function __construct() { parent::__construct("USERLEVEL"); }
public function helloB(){
echo "B";
}
}
Class Connection
class Connection extends dbData{
private $table;
function __construct($name){
$this->setTable($name);
parent::__construct();
}
public function setTable($name){
$this->table = parent::getTable($name);
}
public function connectionInsert($info){
return parent::insert($this->table, $info);
}
public function connectionSelect($where="", $bind="", $fields="*"){
return parent::select($this->table, $where, $bind, $fields);
}
public function connectionDelete($where, $bind=""){
return parent::delete($this->table, $where, $bind);
}
public function connectionRun($sql, $bind=""){
return parent::run($sql, $bind);
}
public function connectionEdit($info, $where, $bind){
return parent::update($this->table, $info, $where, $bind);
}
}
Testing File
$a = new a();
print_r($a);
$b = new b();
print_r($b);
Results:
a Object ( [table:Connection:private] => tokens [error:Db:private] => [sql:Db:private] => [bind:Db:private] => [errorCallbackFunction:Db:private] => [errorMsgFormat:Db:private] => )
a Object ( [table:Connection:private] => tokens [error:Db:private] => [sql:Db:private] => [bind:Db:private] => [errorCallbackFunction:Db:private] => [errorMsgFormat:Db:private] => )
But if i do a print_r directly of the new A() or new B()
print_r(new a());
print_r(new b());
The result is what i want to get.
a Object ( [table:Connection:private] => tokens [error:Db:private] => [sql:Db:private] => [bind:Db:private] => [errorCallbackFunction:Db:private] => [errorMsgFormat:Db:private] => )
B Object ( [table:Connection:private] => us_level [error:Db:private] => [sql:Db:private] => [bind:Db:private] => [errorCallbackFunction:Db:private] => [errorMsgFormat:Db:private] => )
Even when i'm trying to access the functions of each class, suddenly i've got the error saying that function doesn't exist on that class.
Testfile
$a = new a();
print_r($a->helloA());
$b = new b();
echo "</br>";
print_r($b->helloB());
Error Message:
Fatal error: Call to undefined method a::helloB()
So, at this point i've no clue why i'm getting the objects overwritten.
Anybody can help?
Thanks