interface A { public function code();}interface B { public function code(string $string);}class C implements A,B {//...code}
When C needs to implement both interfaces at the same time, what is the method of using the code method in a A-B two interface????
Local testing can only use one of these methods
Reply content:
interface A { public function code();}interface B { public function code(string $string);}class C implements A,B {//...code}
When C needs to implement both interfaces at the same time, what is the method of using the code method in a A-B two interface????
Local testing can only use one of these methods
PHP cannot overloading (same method name, but inconsistent parameters), can be overriding in inheritance (same as method name, regardless of the parameters are consistent).
This means that PHP's parameters change, as long as the method name is the same as the same method of this class.
Of course, as a dynamic language, we can use the Magic method to simulate the Java overloading reference: Http://php.net/manual/en/lang ...
There is a rough way, you put the specific logic of the AB interface is integrated into the C interface, directly call the C interface ^_^
Func_get_args Http://php.net/manual/en/func ...
In itself this kind of writing is a trial error, the public method written in the outside, the class directly called, not every mouth is written in the same, maintenance is also a big trouble
You can learn about PHP traits.
PHP does not support polymorphism, so it is best to avoid this notation