PHP学习笔记4 - 面向对象

 

 

重载

 

PHP不允许函数重载,但有解决重载问题的方法:实现__call方法

 

public function __call($method, $p) {

         if ( $method == ‘display’ ) {

                   if (is_object p[0]) //类对象

                            $this->displayObject($p[0]);

                   else if(is_array($p[0])) // 数组

                            $this->displayArray($p[0]);

                   else

                            ……

}

}

 

 

继承

 

PHP不允许多重继承。

 

 

Per_Class常量与静态方法:

 

class Math {

         const pi = 3.1415926;

         static function sum($num) {

         }

}

Math::pi;

Math::sum($num);

 

 

克隆对象

 

$c = clone $b;

 

可以实现__clone()方法以进行更复杂的操作。

 

 

__autoload()方法

在找不到类实例的时候自动调用本方法。

 

 

其他

 

__toString()方法

 

ReflectionClass 反射API

 

迭代器 Iterator接口 IteratorAggregate接口

 

 

posted @ 2008-07-27 14:21  东捣CY  阅读(241)  评论(0编辑  收藏  举报