ThinkPHP _ initialize method instance analysis, thinkphpu method example
This example describes the _ initialize method in thinkPHP. We will share this with you for your reference. The details are as follows:
The _ initialize method of the subclass automatically calls the _ initialize method of the parent class. Construct of php, if you want to call the method of the parent class, you must call parent :__ construct () in the subclass construct display ();
<? Phpclass BaseAction extends Action {// inherits Thinkphp protected function _ initialize () {// echo "Base class ";}}
If the subclass does not have the _ initialize method, the _ initialize method of the parent class is called by default.
Output: Base class
If yes, execute your own _ initialize method.
Output: hello I am child
If the statement is executed at the same time, write the statement as follows:
<? Phpclass IndexAction extends BaseAction {public function _ initialize () {// If the subclass has initialize, the content of the parent class parent: _ initialize () is not executed (); // Add this sentence to execute the initialization function echo "hello I am child";} of the parent class ";}}
Output: Base class hello I am child