Php 无法为类内的静态变量赋值
我试图为一个类实现单例模式。我有一个静态变量$classInstance,分配类对象时出现错误“Parse error:syntax error,unexpected'=”Php 无法为类内的静态变量赋值,php,oop,Php,Oop,我试图为一个类实现单例模式。我有一个静态变量$classInstance,分配类对象时出现错误“Parse error:syntax error,unexpected'=” 错误是因为使用self关键字访问类的静态属性时缺少“$” /** * Create the client connection. */ public static function createClient() { if (self::$classInstance === null) {
错误是因为使用self关键字访问类的静态属性时缺少“$”
/**
* Create the client connection.
*/
public static function createClient() {
if (self::$classInstance === null) {
self::$classInstance = new self(); // Note the $ sign.
}
return self::$classInstance;
}
/**
* Create the client connection.
*/
public static function createClient() {
if (self::$classInstance === null) {
self::$classInstance = new self(); // Note the $ sign.
}
return self::$classInstance;
}