类的静态变量访问
2016-04-16 23:29
351 查看
<?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 />运行完成!'; ?>
相关文章推荐
- 美国卫星撞月球 测试是否有水耗资7000多万美元
- JNDI定义tomcat资源
- ATF走进清华,阿里技术天团畅谈技术梦想
- 第3周 C语言及程序设计初步例程-42 将数据输出到文本文件
- [026]文本分类之SVM
- 解决vncserver看不到桌面的问题
- NOIP2008 普及组T2 排座椅 解题报告-S.B.S
- 初探JAVA中I/O流(二)
- 软件对存储性能的影响
- 软件对存储性能的影响
- 20145227 《Java程序设计》第7周学习总结
- OSChina 周日乱弹 ——老公 老公 我想吃糖!晚上带你吃
- 王高利:Redis入门
- PicketLink入门指南
- 中秋快乐
- 使用原生javascript实现ajax提交form表单
- 欢迎使用CSDN-markdown编辑器
- 配置 Apache 服务器支持 PHP 文件的解析
- 判断100以内的质数(素数)
- POJ 3616 B - Milking Time dp(深搜超时)