PHP中的函数重载

 

1 <?php
2  class overLoad {
3 public function __call($method,$p){
4 if ( $method=="display" ) {
5 if ( is_int($p[0]) ) {
6 $this->displayint($p[0]);
7 } elseif( is_array($p[0]) ) {
8 $this->displayarray($p[0]);
9 } else {
10 $this->displaystring($p[0]);
11 }
12 }
13 }
14 public function displayint($p){
15 echo "我是整数!<br />";
16 echo $p;
17 }
18 public function displayarray($p){
19 echo "我是字符串!<br />";
20 print($p);
21 }
22 public function displaystring($p){
23 echo "我是数组!<br />";
24 print_r($p);
25 }
26 }
27  /**/
28  $ol = new overLoad();
29
30  $ol->display(99999);
31 $ol->display("wgw8299");
32 $ol->display(array("wgw","tiwer"));

 

 

posted @ 2010-10-20 12:05  wgw8299  阅读(108)  评论(0)    收藏  举报