Was
php?name=php ">phpis not supported
functionHeavy-duty!
PHP, as a weakly typed language, cannot itself be overloaded like a strong type, such as Java, C + +, as a direct implementation. However, it is possible to implement overloading indirectly by some means.
1. You can use the Func_get_args () and Func_num_args () functions to implement the functions of overloading!!
PHP Code:
function rewrite () { $args = Func_get_arg S (); if ( func_num_args () = = 1 ) {func1 ( $args [0< span>]); Else if ( func_num_args () = = 2 ) {Func2 ( span> $args [0], $args [1 ]); }} function func1 ( $arg ) { echo $arg ; } function func2 ( $arg 1 , $arg 2 ) {
echo
$arg 1 , ',
$arg 2
; } rewrite ( ' PHP ');
//
call func1 rewrite (' PHP ', ' China ');
//
Call Func2
2. Use the default values to get the results you want based on the input:
function Test ($name= "Xiao Li",$age= "All") { echo$name. $age ; } Test (); Echo "
"; Test ("a"); Echo "
"; Test (
http://www.bkjia.com/PHPjc/777735.html www.bkjia.com true http://www.bkjia.com/PHPjc/777735.html techarticle originally php?name=php "PHP is not support function overloading!" PHP, as a weakly typed language, cannot itself be overloaded like a strong type, such as Java, C + +, as a direct implementation. But you can pass some ...