我用
PHP编写了一个类,我在标有星号(*)的行上遇到致命错误(标题)
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; } }
我无法弄清楚导致它的原因,以下类(同一文件)返回相同的错误.
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,$f){ self::$id=$a; self::$name=$b; self::$type=$c; self::$ability=$d; self::$desc=$e; self::$cost = $f; } }
您应该使用关键字static声明您的属性,例如
原文链接:/php/138377.htmlstatic private $id = 0;