You’ve got a couple of problems:
- 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. - 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);
?>
Outputs:
Connect Object
(
[logged] => 1
)
1
is what true
prints.
11
solved Trying to get property of non-object php error [duplicate]