[Solved] 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 }.

Demo:

<?php

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

$user = new Connect;
$user->login('test','test');
print_r($user);

?>

http://codepad.org/AVw0k9sY

Outputs:

Connect Object
(
    [logged] => 1
)

1 is what true prints.

11

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