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.