11

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

因为我没有将它实例化为对象,$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();
4

2 回答 2

29

你必须使用self::$some_variable. 把美元放进去。

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

成员变量也必须声明为静态的。

于 2009-11-17T19:04:20.023 回答
6

也将变量声明为静态。

private static $some_variable;
于 2009-11-17T18:39:49.980 回答