interface-php multi-Interface method repetition problem

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.