我用以下代码将一个网站上传到一个实时服务器上。
class Model extends Database
{
public $errors = array();
public function __construct()
{
// code...
if(!property_exists($this, 'table'))
{
$this->table = strtolower($this::class) . "s";
}
}
}但是我一直得到这个错误: PHP致命错误:不能使用动态类名:类--我尝试过使用get_class()函数,但我认为我没有正确地使用它,因为它占用了控制器在其他块中没有找到的页面
public function __construct()
{
// code...
$URL = $this->getURL();
if(file_exists("../private/controllers/".$URL[0].".php"))
{
$this->controller = ucfirst($URL[0]);
unset($URL[0]);
}else
{
echo"<center><h1>controller not found: " . $URL[0] . "</h1></center>";
die;
}这是我一直在使用它的方式
if (!property_exists($this, 'table'))
{
$this->table = strtolower(get_class($this)) . "s";
}发布于 2022-05-15 00:05:58
$this::class是无意义的,因为不能对对象的实例使用范围解析运算符.相反,对当前类使用默认的预定义常量__CLASS__。或函数get_class(object $object = ?): string从任何对象的实例中获取类。
https://stackoverflow.com/questions/72244589
复制相似问题