Home > Article > Backend Development > The performance of destructor method in inheritance in PHP construction method. Linked list needs to be destructed. C# destructor is used for destructor function.
This article shares with you the performance of the destructor method of the PHP constructor in inheritance for your reference. The specific content is as follows
When there is no constructor defined in the subclass, the constructor of the parent class will be automatically called. Therefore, when instantiating a subclass, you need to follow the constructor method of the parent class.
modified to:
If the subclass defines its own constructor, the constructor of the parent class will not be automatically called, but it can be called manually: parent::__construct();
But usually , in subclasses, many times, in the constructor method, you should (need) call the constructor method of the parent class to save code and increase readability:
When there is no destructor method defined in the subclass, it will Automatically call the destructor method of the parent class. If a subclass defines its own destructor method, the destructor method of the parent class will not be automatically called, but it can be called manually: parent::__destruct(). Override
Override is also called overwriting, which means to re-define the properties or methods inherited from the parent class - that is, to write them from scratch.
But note: subclasses override the methods of the parent class. Although you can call the method of the same name of the parent class to complete certain work, it is not necessary. It is also possible that the execution result of the method of the parent class is not suitable for the subclass, and in this case the subclass will write it entirely by itself.
Basic requirements for rewriting:
Access control permissions: The access control permissions of subordinates should be no less than those of superiors: Superior: public Subordinate: only public Superior: protected Subordinate: protected, public Superior: private Subordinate: private protected public - actually this case is meaningless. Private ones cannot be overwritten, but treated as entirely new.
The parameter form of the method: should be consistent with the parent class.
Problem with overriding private properties and private methods: Private properties and methods cannot be overridden, but in fact, subclasses can define properties or methods with the same name that are private to the parent class. Just treat it as a new attribute or method of its own. However, the parameters of the methods must be consistent. Constructor method rewriting problem: Not only can the constructor method be rewritten like other ordinary methods, but it is also more relaxed than ordinary methods: the parameters can be inconsistent when overriding.
Final class:
Usually, if a class is not specifically declared, "others" can take it and use it and "extend" it - inheritance.
However:
If a class does not wish to be extended, it can be declared as a "final class".
Form:
final class class name {. . . . Class definition. . . . }
Final methodFinal method
Usually, if a method is not specifically declared, subordinate classes can "override" (override) it.
But:
If a method does not want to be overridden by subordinate classes, it can be designated as a "final method".
Form:
final function method name (){. . . . Method definition. . . . }
The above is the entire content of this article, I hope it will be helpful to everyone’s study.
The above introduces the performance of the destructor method in inheritance in the PHP construction method, including PHP and destruction content. I hope it will be helpful to friends who are interested in PHP tutorials.