Home >php教程 >php手册 >php函数重载的替代方法--伪重载详解

php函数重载的替代方法--伪重载详解

WBOY
WBOYOriginal
2016-06-06 20:04:131495browse

对于弱类型语言来说,PHP函数重载,并不像一般的OOP那样。而弱类型本来就不区分,所以无法通过这些来实现。但是,可以通过下面的方法来实现简单的伪重载吧。

函数重载的替代方法-伪重载,下面看一个具体的实例代码。

test1( $_arg [ 0 ] ); break ; case 2 : $this -> test2( $_arg [ 0 ] , $_arg [ 1 ]); break ; default : $this -> a = 0 ; $this -> b = 1 ; break ; } } function test1 ($a) { $this -> a = $a ; } function test2 ($a, $b) { $this -> a = $a ; $this -> b = $b ; } } ?>

以上所述就是本文的全部内容了,希望大家能够喜欢。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn