Subclass rewriting of parent class attributes .... Solve the problem of rewriting the parent class attribute of the php subclass
Sal ;}} class Manager extends Employer {protected $ sal = 5000; public function getParentSal () {return parent: getSal (); // call the parent class method to return the parent class property, why is the 5000} public function getSal () {return $ this-> sal ;}}$ manager = new Manager; echo $ manager-> getParentSal (). PHP_EOL; // 5000 why is it 5000, but the version below 5.3 seems to be 3000 ???? Echo $ manager-> getSal (); // 5000?>
Reply to discussion (solution)
Why not?
5.2.10
5000 5000
5.4.20
5000 5000
Why not?
5.2.10
5000 5000
5.4.20
5000 5000
Can the moderator describe in detail? Why do I use parent: To access the attributes of the parent class? how do I read the attributes of the child class? How is the rewrite method used for rewriting?
Protected is only a protection mode, and will naturally be covered by the quilt class.
Replace protected with private.