0

As you see in below PHP code there are two classes A & B. In both show methods defined but with different arguments.

<?php
class A{
  public function show($fvar,$svar){
    echo 'In second.';
  }
}
class B extends A{
  public function show(){
    echo 'In first ';
  }
}

$obj=new B();
$obj->show("First Var","Second Var");
?>

// Output : In first

As per my understanding of object oriented programming call to show function need to execute method in A. What I am missing here ? Does there exist different rules in PHP.

WeAreRight
  • 885
  • 9
  • 24
  • Method `show` exists in B, so it is run. Nothing strange. – u_mulder Mar 31 '17 at 16:58
  • PHP does not support function overloading in that manner. You can read up on PHP's implementation [here](http://php.net/manual/it/language.oop5.overloading.php). – aynber Mar 31 '17 at 16:59
  • @u_mulder yes but I am calling show with arguments. And there exists method show in class A which can receive arguments – WeAreRight Mar 31 '17 at 17:00
  • More information about the differences can be found [here](http://softwareengineering.stackexchange.com/questions/165467/why-php-doesnt-support-function-overloading). – aynber Mar 31 '17 at 17:00
  • PHP works not as you expected, more info in manuals and links provided. – u_mulder Mar 31 '17 at 17:01

0 Answers0