class StaticMethod
{
public $a=10;
public $b=20;
public static function sum(){
return (self::$a+self::$b);
}
}
echo StaticMethod::sum();
答案 0 :(得分:0)
您已将sum
方法声明为静态,但您未将变量$a
和$b
声明为静态。
class StaticMethod
{
public static $a = 10;
public static $b = 20;
public static function sum() {
return (self::$a + self::$b);
}
}
echo StaticMethod::sum(); //returns 30