这是一个来自php的程序。我无法从静态函数中打印受保护变量的值。这个程序有什么问题?
class SomeClass
{
protected $_someMember;
public function __construct()
{
$this->_someMember = 1;
self::getSomethingStatic();
}
public static function getSomethingStatic()
{
echo $_someMember * 5;
}
}
$obj = new SomeClass();
答案 0 :(得分:3)
你希望做这样的事情
class SomeClass
{
protected static $_someMember = <default value>;
public function __construct()
{
self::getSomethingStatic();
}
public static function getSomethingStatic()
{
echo static::$_someMember * 5;
}
}
$obj = new SomeClass();
答案 1 :(得分:2)