1

I want to have this interface:

interface Resource_Controller_Interface {
    public function index_get():stdClass;
    public function index_get(mixed $key):array;
    public function index_post():bool;
    public function index_put(mixed $key):bool;
    public function index_patch(mixed $key):bool;
    public function index_delete(mixed $key):bool;
}

Unfortunately, I cannot do two methods called 'index_get', even with different signatures.

I really want this interface to have these names though, is there a way I can do it? (using $key = null will not force implementation...)

Amit
  • 5,924
  • 7
  • 46
  • 94
  • 1
    possible duplicate of http://stackoverflow.com/questions/4697705/php-function-overloading – Jay Blanchard Jun 23 '16 at 20:29
  • in general, cases like this are best handled by using both an interface and an abstract class, then you can have slightly modified version of the name in the interface ( to force implementation ) and then in the abstract class have a third function that sort of brings those together, if that makes sense. Just a thought. – ArtisticPhoenix Jun 23 '16 at 21:13

1 Answers1

1

You can make use of the func_num_args() and func_get_arg() to get the arguments passed, and use them normally.

This way the function name will be same but you will be able to do different things using some conditionals.