Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法为类内的静态变量赋值_Php_Oop - Fatal编程技术网

Php 无法为类内的静态变量赋值

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

我试图为一个类实现单例模式。我有一个静态变量$classInstance,分配类对象时出现错误“Parse error:syntax error,unexpected'=”


错误是因为使用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;
  }