PHP学习笔记二十二【静态方法二】
<?PHP class Student{ public static $fee; public $name; //构造函数 function __construct($name) { $this->name=$name; } //入学,静态方法无法操作非静态变量,因为静态方法(变量)是属于类,而非静态的成员变量时属于对象的 static function enterSchool($ifee) { self::$fee+=$ifee; } } $student1=new Student("张三"); Student::enterSchool(100); //$student1->enterSchool(100); $student2=new Student("李四"); Student::enterSchool(100); echo "<br/>总学费".Student::$fee; ?>