PHP implements class function overloading by magic method __call
Since PHP is a weakly typed language, it is not overloaded like C + + by changing the type of function return value and the number of arguments to the function! But in the actual development may have the overloaded function the demand, in order to satisfy the development demand, we can use the Magic Method __call () to implement the function overloading !
function __call ($fun, $argv) { if ($fun = = "Assign") { if (count ($argv) ==1) { $ THIS->ASSIGN1 ($argv [0]); } ElseIf (count ($argv) ==2) { $this->assign2 ($argv [0], $argv [1])} } // The Assign function accepts the parameter function assign2 ($key, $value) { if (isset ($key) &&!empty ($value)) { $this val["$key"]= $value; } else{ exit ("ERROR: Please set Variable"); } } Overloaded Assign function accepts array function ASSIGN1 ($array) { if (!empty ($array)) { foreach ($array as $key = $value) { $this->val["$key"]= $value; } else{ exit ("ERROR: Please set array");}}}