文字列リソースを PHP に格納する方法のレシピを試していますが、うまく動作しないようです。配列とオブジェクトに関して __get 関数がどのように機能するかについては、少しわかりません。
エラー メッセージ: 「致命的なエラー: 34 行目の /var/www/html/workspace/srclistv2/Resource.php で stdClass 型のオブジェクトを配列として使用できません」
私は何を間違っていますか?
/**
* Stores the res file-array to be used as a partt of the resource object.
*/
class Resource
{
var $resource;
var $storage = array();
public function __construct($resource)
{
$this->resource = $resource;
$this->load();
}
private function load()
{
$location = $this->resource . '.php';
if(file_exists($location))
{
require_once $location;
if(isset($res))
{
$this->storage = (object)$res;
unset($res);
}
}
}
public function __get($root)
{
return isset($this->storage[$root]) ? $this->storage[$root] : null;
}
}
QueryGenerator.res.php という名前のリソース ファイルは次のとおりです。
$res = array(
'query' => array(
'print' => 'select * from source prints',
'web' => 'select * from source web',
)
);
そして、ここに私がそれを呼ぼうとしている場所があります:
$resource = new Resource("QueryGenerator.res");
$query = $resource->query->print;