Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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_Scope - Fatal编程技术网

在PHP中,如何在单独的类中调用静态变量?

在PHP中,如何在单独的类中调用静态变量?,php,oop,scope,Php,Oop,Scope,如何在PHP中访问单独类中的静态变量?范围解析操作员是否是作业的错误工具?例如: class DB { static $conn = 'Connection'; } class User { function __construct() { DB::conn; //throws "Undefined class constant 'conn' error. } } 如果变量名是属性,则需要在其前面加$ 如果它是一个属性,则需要在变量名之前加上$。Ha,我需要停止调用它

如何在PHP中访问单独类中的静态变量?范围解析操作员是否是作业的错误工具?例如:

class DB {
  static $conn = 'Connection';
}



class User {
  function __construct() {
    DB::conn; //throws "Undefined class constant 'conn' error.
  }
}
如果变量名是属性,则需要在其前面加$


如果它是一个属性,则需要在变量名之前加上$。

Ha,我需要停止调用它。在C#和PHP之间切换让我完全忽略了令人讨厌的丢失的$符号!谢谢你的快捕指示牌!哈,我今天就到此为止。在C#和PHP之间切换让我完全忽略了令人讨厌的丢失的$符号!谢谢你的快捕指示牌!
DB::$conn