Possible Duplicate:
Call to a member function on a non-object – works localhost but not online
don’t know how to solve this problem, it’s basic but can’t find a solution.
I use two files: connect.php and user.php.
in connect.php is a Connect class:
class Connect{
var $logged;
function login($username, $password){
..more code..
if($pass==$password){
$this->logged=true; // db connection is fine, this works
// checked it with echo $this->logged;
}
}
}
and when i call it from another file, user.php like this:
$user=new Connect;
$user->login();
echo $user->logged; // ERROR Trying to get property of non-object
Why is this code not working, but it works offline (locally)???
You’ve got a couple of problems:
$user->login, PHP is assuming you’re accessing an object property, not the function; you need$user->login()(note the()), which will call the method.}.Demo:
http://codepad.org/AVw0k9sY
Outputs:
1is whattrueprints.