Trying to get property of non-object php error [duplicate]

You’ve got a couple of problems:

  1. When you call $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.
  2. Your example is missing a }.



class Connect{
    var $logged;
    function login($username, $password){
        if($pass == $password){
            $this->logged = true;

$user = new Connect;



Connect Object
    [logged] => 1

1 is what true prints.

Leave a Comment