Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.