I've made a class in PHP and I'm getting a Fatal Error(Title) on the line marked with an asterisk(*)
class monster{
    private $id = 0;
    private $name = "";
    private $baseLevel = 0;
    private $attack = 0;
    private $defense = 0;
    private $baseEXP = 0;
    private $dropType = 0;
    private $dropNum = 0;
    function __construct($a, $b, $c, $d, $e, $f, $g, $h){
    *   self::$id=$a;
        self::$name = $b;
        self::$baseLevel = $c;
        self::$attack = $d;
        self::$defense = $e;
        self::$baseEXP = $f;
        self::$dropType = $g;
        self::$dropNum = $h;
    }
}
I can't figure out what's causing it, also, the following class(same file) is returning the same error.
class item{
    private $id = 0;
    private $name = "";
    private $type = 0; #0-weapon, 1-armor, 2-charm, 3-ability
    private $ability = 0;
    private $desc = "";
    private $cost = 0;
    function __construct($a, $b, $c, $d, $e, $f){
        self::$id=$a;
        self::$name=$b;
        self::$type=$c;
        self::$ability=$d;
        self::$desc=$e;
        self::$cost = $f;
    }
}
Do you happen to know what's causing the error or how I can fix it?
You should declare your properties with keyword static, e.g.
private static $id = 0;
                        Use $this-> instead of self::
Self is for static members and $this is for instance variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With