<code>interface A { public function code(); } interface B { public function code(string $string); } class C implements A,B { //...code }</code>
When C needs to implement these two interfaces at the same time, is there any way to use the code methods in the two interfaces A and B at the same time? ? ? ?
Local testing can only use one of the methods
<code>interface A { public function code(); } interface B { public function code(string $string); } class C implements A,B { //...code }</code>
When C needs to implement these two interfaces at the same time, is there any way to use the code methods in the two interfaces A and B at the same time? ? ? ?
Local testing can only use one of the methods
PHP cannot be overloaded (same method name, but parameters are inconsistent), but can be overriding in inheritance (same method name, regardless of whether the parameters are consistent).
In other words, no matter how the parameters of PHP change, as long as the method name is the same, it will be regarded as the same method of this class.
Of course, as a dynamic language, we can simulate Java's overloading through magic methods. Reference: http://php.net/manual/en/lang...
There is a crude method. You integrate the specific logic of the AB interface into the C interface and directly call the C interface^_^
func_get_args http://php.net/manual/en/func...
This way of writing itself is just a trial and error. Public methods are written outside and called directly in the class. Don’t write the same thing in every port, which is also very troublesome to maintain.
You can learn about the characteristics of PHP.
php does not support polymorphism, so it is best to avoid this way of writing