The parameters of the methods in the PHP interface can be inconsistent with the parameters in the implementation class method

Source: Internet
Author: User
Interface Dispatch2{public function Getcontroller ();} Class QueryString implements Dispatch2{public function Getcontroller ($url = ', $url 2 = ') {echo ' 234 ';}} $b = new QueryString (); Echo $b->getcontroller ();

The above procedures can be normal operation, it is understood that Java inside like this usage is not possible, and this usage seems to be quite unreasonable, why in PHP can be used?

Reply content:

Interface Dispatch2{public function Getcontroller ();} Class QueryString implements Dispatch2{public function Getcontroller ($url = ', $url 2 = ') {echo ' 234 ';}} $b = new QueryString (); Echo $b->getcontroller ();

The above procedures can be normal operation, it is understood that Java inside like this usage is not possible, and this usage seems to be quite unreasonable, why in PHP can be used?

The function Call of PHP is to find the function that corresponds to the function name by checking the table.

PHP's function overloading differs from other languages in that it receives a different number of arguments, actually passing it as an array to the function.

So the function call you enumerate, without parameters, can be executed because the argument array is empty, which is reasonable.

PHP function calls do not check for matching of the number of parameters.

Reference: Here
And here it is.

  • 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.