-2
class StaticMethod
{

public $a=10;

public $b=20;

    public static function sum(){
        return (self::$a+self::$b);
    }
}

echo StaticMethod::sum();
u_mulder
  • 54,101
  • 5
  • 48
  • 64
Selvesan Malakar
  • 511
  • 2
  • 7
  • 20

1 Answers1

0

You declared your sum method as static, but you didn't declare your variables $a and $b as static.

class StaticMethod
{
    public static $a = 10;
    public static $b = 20;

    public static function sum() {
        return (self::$a + self::$b);
    }
}

echo StaticMethod::sum(); //returns 30
romellem
  • 5,792
  • 1
  • 32
  • 64