如何在静态方法中调用类的成员变量?

Ric*_*ard 10 php variables static-methods class

我正在使用一些方法来自动加载带有函数的辅助文件.我现在唯一的问题是如何调用该类中的变量.

因为我没有将它实例化为对象,所以$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;
    }
}
Run Code Online (Sandbox Code Playgroud)

我现在可以在任何地方调用该功能spl_autoload_register().

some_helperclass:: some_func();
Run Code Online (Sandbox Code Playgroud)

Gal*_*len 27

你必须使用self::$some_variable.把$放在那里.

http://www.php.net/manual/en/language.oop5.static.php

成员变量也必须声明为static.


Byr*_*ock 5

将变量声明为静态.

private static $some_variable;
Run Code Online (Sandbox Code Playgroud)