I am getting the following error:
PHP Fatal error: Access level to Database::$db must be public (as in class phpLive) in C:\Users\ryannaddy\Documents\NetBeansProjects\phpLive\plugins\Database\Database.plugin.php on line 92
Fatal error: Access level to Database::$db must be public (as in class phpLive) in C:\Users\ryannaddy\Documents\NetBeansProjects\phpLive\plugins\Database\Database.plugin.php on line 92
Part of class phpLive.php
. This is how my Database::$db property gets created. As you can see it is a dynamically created property. I then use __get()
to access the property like in my next block of code.
<?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;
}
}
Note: $class
and $info
are loaded from a config file that looks like this:
$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",
)
),
);
This is how I use the property db
<?php
require_once '../../phpLive.php';
$live->db->select("select * from users where fname in(?,?)", array("Billy", "Bob"))->each(function($col, $name){
echo "here";
});
So, the method select
is in class/file Database.plugin.php
which extends phpLive
class Database extends phpLive{
public function select(){
$info = $this->queryinfo(func_get_args());
$this->query($info->query, $info->args);
return $this;
}
}
The select works fine, but as soon as I add the each method (found in the phpLive
class) I get the above error. What can I do to make this work?
There must be a private variable named $db in file Database.plugin.php or its children class.