扩展简单类时出现致命错误

时间:2012-08-08 07:14:41

标签: mysqli php

我有简单的行class autorization extends mysql,它导致致命错误:在...中的非对象上调用成员函数close()在该行上

function __destruct(){
        $this->connection->close();
    }

构造

$mysqli = new mysqli(*****);
$this->connection = $mysqli;

目前没有其他方法没有使用类mysql

2 个答案:

答案 0 :(得分:1)

未初始化连接属性。如果在mysql类中有构造函数,请确保通过在autorization类中指定构造函数来完全覆盖它。这可以通过添加:

来实现
parent::__constructor( any_params_to_mysql_go_here );

从你的问题来看,不清楚是谁维护了连接属性:mysql类是不是?

答案 1 :(得分:0)

用于测试目的尝试

function __destruct(){
    if ( !is_object($this->connection) ) {
        echo ' $this->connection is not an object', "\n";
        var_dump($this->connection);
        die;
    }
    if ( !method_exists($this->connection, 'close') ) {
        echo '$this->connection has no method close()', "\n";
        echo get_class($this->connection), "\n";
        die;
    }
    $this->connection->close();
}
相关问题