What is the difference between PHP overloading and rewriting? What is the difference between overloading and other languages, such as Java?

Source: Internet
Author: User
Problem:
The contents of the PHP manual for overloading are as follows: PHP provides a "reload" (overloading) that refers to dynamically "create" class properties and methods.
We do this by means of magic methods.
such as __call ($funcname, $arguments), __callstatic ($funcname, $arguments)

Overloading in the Java language refers to the ability to create multiple methods in a class that have the same name but have different parameters and different definitions.

Methods are invoked by the number of different arguments and parameter types passed to them to determine which method to use.

Question: PHP and Java on the concept of overloading is certainly a difference, but do not know what the real difference is?

Reply content:

Problem:
The contents of the PHP manual for overloading are as follows: PHP provides a "reload" (overloading) that refers to dynamically "create" class properties and methods.
We do this by means of magic methods.
such as __call ($funcname, $arguments), __callstatic ($funcname, $arguments)

Overloading in the Java language refers to the ability to create multiple methods in a class that have the same name but have different parameters and different definitions.

Methods are invoked by the number of different arguments and parameter types passed to them to determine which method to use.

Question: PHP and Java on the concept of overloading is certainly a difference, but do not know what the real difference is?

Java is a strongly-typed

public class DataArtist {    ...    public void draw(String s) {        ...    }    public void draw(int i) {        ...    }    public void draw(double f) {        ...    }    public void draw(int i, double f) {        ...    }}

PHP's so-called overloading, just a similar rewrite of some magical methods
There's a good word in the comments.

This article should call this technique "interpreter hooks".

  • Related Article

    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.