Questions about php subclass reloading parent class private methods

Source: Internet
Author: User
Questions about php subclass reloading parent class private methods
 test(10);?>

In the above code:
Although subclass B inherits A, test () in Class A is A private method and should not be inherited in principle. why do I define A test () with the same name but different parameters in Class B () will an error be reported? is this a heavy load error?


Reply to discussion (solution)

 test($a);}}$var1=new B;$var1->test1(10);?>

If you set public in B to private, no error will be reported.

Do you know what's going on with the error message?

Do you know what's going on with the error message?


I know the cause of the error is rewriting, but I have two questions:
1. isn't the private method of the parent class inherited? why is it overwritten?
2. Why does public and protected in the subclass report an error while private does not?
class B extends A{        public function test($a){            echo "testB".$a;        }}

Could you please explain it?

Overwrite or overwrite
The coverage condition is that the protection mode is consistent with the parameter
This kind of drag from java violates the original intention of php and eventually leads to the death of php.

Even C # is launching a "dynamic language", and php is still gradually static. isn't that a step backwards?

Overwrite or overwrite
The coverage condition is that the protection mode is consistent with the parameter
This kind of drag from java violates the original intention of php and eventually leads to the death of php.

Even C # is launching a "dynamic language", and php is still gradually static. isn't that a step backwards?


Isn't overwriting or overwriting a meaning?
Maybe I didn't express it clearly. I mean, isn't the private test () method in the parent class not inherited? in theory, in the subclass, I can start a function named test, and the parameter list is arbitrary, but this code will report an error. So can't inherited methods be overwritten?
 test(10);?>

The following code is in the subclass. if it is rewritten, why is the list of parameters inconsistent?
 test($a);}}$var1=new B;$var1->test1(10);?>

B: test is a redefinition, or overwrite (overwrite)
Overload, which is not supported in php

As for the so-called syntax checks, they are all nonsense. it is hard to drag in and slow down the php speed.

B: test is a redefinition, or overwrite (overwrite)
Overload, which is not supported in php

As for the so-called syntax checks, they are all nonsense. it is hard to drag in and slow down the php speed.


That is to say, B: test () has no relationship with the parent class, right? thanks.

Right, right, right

B: test is a redefinition, or overwrite (overwrite)
Overload, which is not supported in php

As for the so-called syntax checks, they are all nonsense. it is hard to drag in and slow down the php speed.


Or there is no rewrite here, but a new function test () is defined in Class B.

But the form is rewritten.

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.