Home > Backend Development > PHP Tutorial > What is the difference between PHP overloading and rewriting? What is the difference between overloading and other languages ​​(such as Java)?

What is the difference between PHP overloading and rewriting? What is the difference between overloading and other languages ​​(such as Java)?

WBOY
Release: 2016-08-04 09:20:43
Original
886 people have browsed it

Question:
The content about overloading in the PHP manual is as follows: The "overloading" provided by PHP refers to dynamically "creating" class attributes and methods.
We do it through magic methods.
  Such as __call($funcname, $arguments), __callStatic($funcname, $arguments)

  Overloading in the JAVA language means that multiple methods can be created in a class. They have the same name but different parameters and different definitions.

When calling methods, determine which method to use based on the number and type of parameters passed to them.

Question: There is definitely a difference in the concepts of overloading between PHP and Java, but I don’t know what the real difference is?

Reply content:

Question:
The content about overloading in the PHP manual is as follows: The "overloading" provided by PHP refers to dynamically "creating" class attributes and methods.
We do it through magic methods.
  Such as __call($funcname, $arguments), __callStatic($funcname, $arguments)

  Overloading in the JAVA language means that multiple methods can be created in a class. They have the same name but different parameters and different definitions.

When calling methods, determine which method to use based on the number and type of parameters passed to them.

Question: There is definitely a difference in the concepts of overloading between PHP and Java, but I don’t know what the real difference is?

Java is strongly typed

<code>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) {
        ...
    }
}</code>
Copy after login

The so-called overloading of PHP is just a similar rewriting of some magic methods
There is a good saying in the comments

This article should call this technique "interpreter hooks".

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template