1

I have two interfaces with same method names. But, both the methods have different signatures. As per my information two interfaces with same method names and same signature will not work. But, in this case signature ( that is number of arguments) are different. Then why program is not working ?

<?php

interface Car {
  public function setModel($name);
}

interface Vehicle {
  public function setModel();
}

class miniCar implements Car, Vehicle {
  private $model;

  public function setModel($name)
  {
    $this -> model = $name;
  }

  public function setModel()
  {
    echo 'do nothing';
  }

}


$obj = new miniCar();

?>
WeAreRight
  • 885
  • 9
  • 24
  • The whole purpose of an interface is to force classes that implements it to have a specific signature, so having two interfaces with different signatures for the same method makes no sense at all, since there is no overloading of methods in PHP. – M. Eriksson Feb 17 '17 at 07:08

1 Answers1

2

PHP functions cannot be overloaded. They must have different names.

PHP function overloading

Community
  • 1
  • 1
E Rullmann
  • 344
  • 3
  • 12