Jump to content

interfaces doubt


Gurzi

Recommended Posts

Hello Guys, i defined an interface for my databases and now i have this method in my interface:

 

public function queryUniqueObject($query, $debug );

 

My problem is that i alwasy done without interfaces this methodas as

 

public function queryUniqueObject($query, $debug =  false );

 

If now i try to use this last method in the class that implements the interface, it says that it has to be like that ( interface ).

 

But in the interface, it doesn't let me put the method like $debug= false.

 

Why ?

 

how can i solve this ?

 

because i really dont want to modify my entire code.

Link to comment
https://forums.phpfreaks.com/topic/102642-interfaces-doubt/
Share on other sites

The following works fine for me:

 

<?php

interface test {

public function method($var, $var1 = false);

}

class example implements test {

public function method($var, $var1 = false){
	// do something
}

}
?>

 

So, as you can see you CAN have a method in an interface that implements a default value inside the method call. Where's the real problem? What error are you getting? Can you post the relevant code?

Link to comment
https://forums.phpfreaks.com/topic/102642-interfaces-doubt/#findComment-526935
Share on other sites

The following works fine for me:

 

<?php

interface test {

public function method($var, $var1 = false);

}

class example implements test {

public function method($var, $var1 = false){
	// do something
}

}
?>

 

So, as you can see you CAN have a method in an interface that implements a default value inside the method call. Where's the real problem? What error are you getting? Can you post the relevant code?

 

It said that i cannot have values defined in interface arguments list.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/102642-interfaces-doubt/#findComment-529251
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.