对数据库的访问级别:$db必须是公共的


Access level to Database::$db must be public

我得到以下错误:

PHP致命错误:在C:''Users''ryanaddy''Documents''NetBeansProjects''phpLive''plugins''Database''Database.plugin.PHP的第92行中,对数据库:$db的访问级别必须是公共的(如phpLive类中)

致命错误:第92行C:''Users''ryanaddy''Documents''NetBeansProjects''phpLive''plugins''Database.plugin.php中对数据库:$db的访问级别必须是公共的(如phpLive类中)

phpLive.php类的一部分。这就是我的Database::$db属性的创建方式。正如您所看到的,它是一个动态创建的属性。然后,我使用__get()来访问该属性,就像在我的下一个代码块中一样。

<?php
class phpLive{
    public function loadPlugin($class, $info){
        $this->functionName = __FUNCTION__;
        $info               = (object)$info;
        $file               = $this->location . "/plugins/" . $info->root . "/" . $info->fileName;
        if(is_file($file)){
            require_once $file;
            $instance                   = (string)$info->instanceName;
            $info                       = (isset($info->information)) ? $info->information : "";
            $reflection = new ReflectionClass($class);
            $this->$instance = $reflection->newInstanceArgs(array($info));
            $this->extension[$instance] = $this->$instance;
            return $this->$instance;
        }
        return false;
    }
    public function __get($name){
        switch($name){
            default:
                if(array_key_exists($name, $this->extension)){
                    $ret = $this->extension[$name];
                }else{
                    $ret = false;
                }
                break;
        }
        return $ret;
    }
}

注意:$class$info是从如下配置文件加载的:

$plugins = array(
    "Database" => array(
        "root"         => "Database",
        "fileName"     => "Database.plugin.php",
        "instanceName" => "db",
        "sessionRef"   => "db",
        "information"  => array(
            "dbtype"   => "mysql",
            "hostname" => "localhost",
            "database" => "test",
            "username" => "root",
            "password" => "xxx",
        )
    ),
);

这就是我如何使用属性db

<?php
require_once '../../phpLive.php';
$live->db->select("select * from users where fname in(?,?)", array("Billy", "Bob"))->each(function($col, $name){
    echo "here";
});

因此,方法select在扩展phpLive 的类/文件Database.plugin.php

class Database extends phpLive{
    public function select(){
        $info = $this->queryinfo(func_get_args());
        $this->query($info->query, $info->args);
        return $this;
    }
}

select工作得很好,但只要我添加each方法(在phpLive类中找到),就会出现上面的错误。我该怎么做才能让它发挥作用?

文件数据库中必须有一个名为$db的私有变量。‌​plugin.php或其子类。