我有一个login.php和authenticate.php
我想访问类中authenticate.php中的一个变量。我想从authenticate类获得错误消息到我的login.php
这是我在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;
}
}
这就是我在login.php 中打印的方式
<?php
$error = new Authenticate();
$error->invalidUserErr();
?>
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();
?>
不要在类中回显变量,而是在login.php上回显方法。如果您无论如何都要实例化对象,则无需将其设为静态函数。
在静态关键字上查看此页面
要访问静态函数,需要
<?php
$error = new Authenticate::invalidUserErr();
?>