Why Function Overloading Is Not Allowed In PHP

As we know that when two or more methods having the same name but with different number of parameters present in the same program is known as function overloading.

Concept of function overloading is not allowed in PHP because of two predined functions named as func_num_args() and func_get_args().
Program which clearly prove that why function overloading is not allowed in PHP.

We are writing a program to find the average of N numbers :

<?php

function average()
{

$nop=func_num_args();//this function is used to count total number of parameters passed by the user while calling a function.

$args=func_get_args();//predefined function used to get the value of parameters passed by user while calling a function.

$sum=array_sum($args);//calculate sum of total observations.

$avg=$sum/$args;

return $avg;

}

echo average(2,4);

echo “<br/>”;

echo average(5,7,9);

echo “<br/>”;

echo average(12,5,7,8);
?>

If you understand this program then ball is in your court because it is one of the favorable question in PHP interview.

Find out positive reviews received by SynapseIndia for their PHP
website development.Employees at SynapseIndia work with motto to provide client satisfaction without giving them any chance to complaints in any cases.