1
這是我的代碼:簡單的ORM結構笨
<?php
class VortexORM {
private static $orm = null;
public function __get($name) {
return $this->$name;
}
public function __set($name, $value) {
$this->$name = $value;
}
public static function getInstance() {
if (VortexORM::$orm == null)
VortexORM::$orm = new VortexORM();
return VortexORM::$orm;
}
public static function set($name, $value) {
$orm = VortexORM::getInstance();
//echo "Setting [ <b>{$name}</b> :: <i>{$value}</i>]";
$orm->$name = $value;
}
public static function get($name) {
$orm = VortexORM::getInstance();
// echo "Getting [ <b>{$name}</b> :: <i>{$orm->$name}</i>]";
return $orm->$name;
}
}
獲取數據我用:
var_dump(VortexORM::get('admin_links'));
var_dump(VortexORM::get('admin'));
設定數據使用:
VortexORM::set('admin_links',array(....));
但是,我得到的以下警告:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: VortexORM::$admin_links
Filename: Vortex/VortexORM.php
Line Number: 8
NULL
A PHP Error was encountered
Severity: Notice
Message: Undefined property: VortexORM::$admin
Filename: Vortex/VortexORM.php
Line Number: 8
爲什麼我會收到這些警告?
我希望能夠訪問它像這樣笨的靜態函數:
$this->vortexorm->admin_links = array(....);