我有一个简单的单例类:
class controller {
// Store the single instance of controller
private static $_controller = null;
public static $user;
public static $db;
public static $page;
public static $code;
// construct the class and set up the user & db instances
private function __construct() {
self::$db = new db(HOST, USER, PASS, DB);
self::$user = new user();
self::$page = new page();
self::$code = new code();
}
// Getter method for creating/returning the single instance of this class
public static function getInstance() {
if (!self::$_controller) {
self::$_controller = new self();
}
return self::$_controller;
}
}
我这样称呼(并测试)它:
$load = controller::getInstance();
print_r($load::$db->query('SELECT * FROM `users`'));
但后来我从 PHP 得到这个错误:
Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM
此代码适用于 PHP 5.3,但不适用于运行 PHP 5.2 的服务器
这里发生了什么?