Posts

Showing posts with the label PHPJobs

Function Overloading And Overriding In PHP

Image
  Function overloading and overriding is the Object Oriented Programming feature in PHP. Function overloading means multiple function have the same name but different parameters. But in case of function overriding, more than one functions will have same method signature and number of arguments. PHP doesn’t support function overloading directly like other languages such as C++, JAVA etc. But we can overcome this issue with using the PHP magic method __call(). So let’s see how overloading and overriding in PHP works. Function Overloading In PHP Function overloading contains same function name and that function performs different task according to number of arguments. Example <?php class Shape { const PI = 3.142 ; function __call($name,$arg){ if($name == 'area') switch(count($arg)){ case 0 : return 0 ; case 1 : return self::PI * $arg[0] ; case 2 : return $arg[0] * $arg[1]; } }