Reputation: 426
I have a login.php and authenticate.php
I want to access a variable inside the authenticate.php inside a class. I want to get the error message from authenticate class to my login.php
This is my class inside Authenticate.php
Class Authenticate {
public $invalidUserErrMsg = "sdfs";
static public function LDAPAuthenticate() {
//connection stuff
} else {
$msg = "Invalid username / password";
$this->invalidUserErrMsg = $msg;
}
}
static public function invalidUserErr() {
echo $hits->invalidUserErrMsg;
return $this->invalidUserErrMsg;
}
}
This is how I'm printing inside login.php
<?php
$error = new Authenticate();
$error->invalidUserErr();
?>
Upvotes: 0
Views: 74
Reputation: 787
Class Authenticate {
public $invalidUserErrMsg = "sdfs";
public function LDAPAuthenticate() {
if($hello) {
echo 'hello';
} else {
$msg = "Invalid username / password";
$this->invalidUserErrMsg = $msg;
}
}
public function invalidUserErr() {
return $this->invalidUserErrMsg;
}
}
<?php
$error = new Authenticate();
echo $error->invalidUserErr();
?>
Don't echo the variable within the class but echo the method on login.php. There is no need to make it a static function if you are going to instantiate the object anyway.
Check out this page on the static keyword
Upvotes: 3
Reputation: 133360
For accessing static function you need
<?php
$error = new Authenticate::invalidUserErr();
?>
Upvotes: 0