我正在使用一些方法来自动加载带有函数的辅助文件。我现在唯一的问题是如何调用该类中的变量。
因为我没有将它实例化为对象,$this
将无效。但是会是什么呢?
class some_helperclass {
var $some_variable = '007';
public static function some_func()
{
//return 'all ok';
if (self::some_variable !== FALSE)
{
return self::ip_adres;
}
}
我可以在spl_autoload_register()
的帮助下随时随地调用该功能。
some_helperclass:: some_func();
答案 0 :(得分:27)
您必须使用self::$some_variable
。把$放在那里。
http://www.php.net/manual/en/language.oop5.static.php
成员变量也必须声明为静态。
答案 1 :(得分:5)
将变量声明为静态。
private static $some_variable;