调用非静态方法时出错


error calling non static method

public  function upload() {
    try {
        $database_connect = new DatabaseConnect();
        $connection = $database_connect->getConnection();
        $this->populate_database($connection); //line 43
        $connection->close();
        return true;
    } catch (Exception $exp) {
        echo $exp->getMessage();
        return false;
    }
}
private function populate_database(mysqli $connection){
    $query = "insert into bases (img_url) values ($this->image_name)";
    $result = $connection->query($query);
    if (!$result) die($connection->error);
    if (!$this->update_linked_table($connection)) {
        echo "linked table not updated";
    }
}

正在调用一个私有的非静态方法,那么为什么我会收到此错误:

致命错误: 不在对象上下文中使用 $this 在/var/www/html/CocExplore/html5BoilerPlate/php/LocalImage.php 第 43 行

非静态调用方法。例如,如果您调用 YourClass::upload() ,请将其替换为类似 $class = new YourClass(); $class->upload();