这篇文章介绍在 PHP 的面向对象编程(OOP)。我将演示如何用面向对象的概念编出较少的代码但更好的程序。祝大家好运。
面向对象编程的概念对每一个作者来说都有不同的看法,我提醒一下一个面向对象语言应有的东西:
- 数据抽象和信息隐藏
- 继承
- 多态性
在PHP中使用类进行封装的办法:
?phpclass Something { // In OOP classes are usually named starting with a cap letter. var $x; function setX($v) { // Methods start in lowercase then use lowercase to seprate // words in the method name example getValueOfArea() $this-x=$v; } function getX() { return $this-x; }}?<...[ 查看全文 ]