0
I would like to know how to create a method in the interface of a program in object orientation, where this method receives parameters... Example I am creating a remote control object where has the function(method) of increasing volume, but for me to increase the volume I need to receive a value from the keyboard to increase the volume, I am using PHP
interface Controlador {
public function ligar();
public function desligar();
public function aumentar_volume();
public function diminuir_volume();
public function abrir_menu();
}
Class page that implements the interface. I put only the block with the function body, not the whole page.
public function aumentar_volume($valor){
if($this->getLigado(true)){
if($this->getVolume <= $this->getVolume_max){
$this->setVolume($this->$getVolume() + $this->getValor);
}else{
echo "Volume já atingiu o volume máximo";
}
}
}
Fatal error: Declaration of Control_remote::aumentar_volume() must be compatible with Controlador::aumentar_volume() in C: xampp htdocs Programas_orientacao_obj Controle_remote Controle_remote.php on line 4
In the interface, you defined the method without arguments, but in the class you defined an argument. That’s the error. If the method has an argument, it must be present in the interface as well.
– Woss
Thank you Anderson but how do I do it? can help me please, I’m not getting this argument on the interface.
– sol25lua
As you tried to do?
– Woss
This way: interface Controller { private $value; public Function on(); public Function off(); public Function increases_volume($value); public Function decreasr_volume(); public Function opens_menu(); }
– sol25lua
Method argument is completely different from class attribute. Argument would be
$valor
in the methodaumentar_volume
.– Woss
This in the interface? or I put in the page that was implemented the interface?
– sol25lua
I’ve got it Thank you.
– sol25lua