Hi all,
Let me show what I did encounter these days while coding some OO code. So here's my IUnique class declaration:
class IUnique extends IObject
{
private $ID;
/** @brief Gets the unique ID of the object
@return Integer
*/
function GetID()
{
return $this->ID;
}
}
IObject is an emptry abstract class, so nothing interesting there.
Then I have another class, IUser which derives from IUnique.
class IUser extends IUnique
{
private $Login;
private $Passwd;
private $Name;
private $Address;
private $Email;
private $Level;
private $MSN;
private $ICQ;
private $Jabber;
/** @brief Constructor
*/
function __construct($ID=0, $Log="", $P="", $N="", $A="", $E="", $L="", $M="", $I="", $J="")
{
// ctor
$this->ID = $ID;
$this->Login = $Log;
$this->Passwd = $P;
$this->Name = $N;
$this->Address = $A;
$this->Email = $E;
$this->Level = $L;
$this->MSN = $M;
$this->ICQ = $I;
$this->Jabber = $J;
}
...
Everything seems fine, right? Then I get some user information from the database and create an IUser object and the strange thing is that the GetID(); method which is derived from IUnique doesn't work. Then I examined the problem closer and after a var_dump(); on the user object that's what I get:
object(IUser)#7 (11) {
["Login:private"]=>
string(5) "admin"
["Passwd:private"]=>
string(0) ""
["Name:private"]=>
string(0) ""
["Address:private"]=>
string(0) ""
["Email:private"]=>
string(0) ""
["Level:private"]=>
string(0) ""
["MSN:private"]=>
string(0) ""
["ICQ:private"]=>
string(0) ""
["Jabber:private"]=>
string(0) ""
["ID:private"]=>
NULL
["ID"]=>
string(1) "1"
}
So it seems that $this->ID = $ID; creates a new variable and the original ID variable which is declared in IUnique is ["ID:private"]=>
NULL. Strange, isn't it? Any ideas why this could be happening? Any help is greatly appreciated.