Click to See Complete Forum and Search --> : [RESOLVED] Call to a member function on a non-object


sasam1400
03-19-2008, 09:14 PM
Hi
i get this message and i don't knw what to do... please help.

this is the code:

class CredentialsHandler
{
var $username;
var $password;
function setUsername($username)
{
$this->username = $username;
}
function setPassword($password)
{
$this->password = $password;
}
function getUsername()
{
return $this->username;
}
function getPassword()
{
return $this->password;
}
}

$credentialsHandler->setUsername('sasam');
$credentialsHandler->setPassword('12345');


I always get message saying:
Fatal error: Call to a member function on a non-object in c:\program files\easyphp1-8\www\mgw\servis.php on line 75
(line 75 is the bold one)

Any ideas?

NogDog
03-19-2008, 09:23 PM
You have to instantiate class as an object before you can use it:

$credentialsHandler = new CredentialsHandler();
$credentialsHandler->setUsername('sasam');

sasam1400
03-19-2008, 09:30 PM
ok.
that solved the problem :D
i'm working on this code 8 hors now... my head is like a basketball or something...

although, i'm new to object oriented programming... so i wouldn't have known this even if i hadn't been tired :D

those 'new's, 'this's and arrows "->" make me confused.

thanx a lot!