标签:
<?php /** * @author keke * @copyright 2016 * 这是一个类的标准格式,用于记忆,静态变量访问:student::$fee */ class student { public static $fee = 0; public $name; function __construct($name) { $this->name = $name; //非静态属性访问格式:$this->name } public static function runCode($fee) { student::$fee += $fee; //这里不能用$this->fee非静态格式访问,是静态变量访问格式:student::$fee } public function returnStr() { return student::$fee; //这里不能用$this->fee非静态格式访问,是静态变量访问格式:student::$fee } } $zhangsan = new student("张三"); $zhangsan->runCode(320); $lisi = new student("李四"); $lisi->runCode(560); //这里不能用( 类::方法 )来访问 echo $lisi->returnStr(); //结果:880 echo ‘<br />运行完成!‘; ?>
标签:
原文地址:http://www.cnblogs.com/qingsong/p/5399809.html