Repeated interface-php multi-interface Methods

Source: Internet
Author: User
{Code...} when C needs to implement both interfaces at the same time, is there any way to use the code methods in both interfaces A and B ???? Only one method can be used for local testing.
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, is there any way to use the code method ????

Only one method can be used for local testing.

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, is there any way to use the code method ????

Only one method can be used for local testing.

Php cannot overloading (the same method name, but the parameters are inconsistent). It can overriding (the same method name, regardless of whether the parameters are consistent) in inheritance ).
That is to say, how to change the php parameters, as long as the method name is the same as the same method of the class.

Of course, as a dynamic language, we can simulate java overloading through magic reference: http://php.net/manual/en/lang...

There is a rough 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 writing method is an attempt error. The public method is written outside and called directly in the class. do not write the same code for every mouth. it is also very troublesome to maintain it.

You can understand the characteristics of PHP.

Php does not support polymorphism, so it is best to avoid this writing.

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.