次のエラーが表示されます。
PHP 致命的なエラー: C:\Users\ryannaddy\Documents\NetBeansProjects\phpLive\plugins\Database\Database.plugin.php の 92 行目で、Database::$db へのアクセス レベルは public (クラス phpLive と同様) である必要があります
致命的なエラー: C:\Users\ryannaddy\Documents\NetBeansProjects\phpLive\plugins\Database\Database.plugin.php の 92 行目で、Database::$db へのアクセス レベルを public (クラス 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
するクラス/ファイルにありますDatabase.plugin.php
phpLive
class Database extends phpLive{
public function select(){
$info = $this->queryinfo(func_get_args());
$this->query($info->query, $info->args);
return $this;
}
}
phpLive
選択は正常に機能しますが、(クラスで見つかった) each メソッドを追加するとすぐに、上記のエラーが発生します。これを機能させるにはどうすればよいですか?