Home  >  Article  >  Backend Development  >  How to ensure the order in which two functions are called in PHP_PHP Tutorial

How to ensure the order in which two functions are called in PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:48:111006browse

In php, how to ensure that before calling a function, another function must be called. Of course, we may soon think of class constructors and member functions. Is there any other way besides this way?

Assume that before calling Search, the Init function must be called. The code can be organized as follows:

[php] function Init(){
//Implementation of init itself
// to do init


//Implementation of Search
// to do search
Function Search(){
}  
}
function Init(){
//Implementation of init itself
// to do init


//Search implementation
// to do search
function Search(){
}
}


In this way, when calling the function Search, Init must be called first. Otherwise, an error will be reported!

For other details, please refer to: http://cn2.php.net/manual/en/language.functions.php

Excerpted from The Pure Land of the Soul

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478446.htmlTechArticleIn php, how to ensure that before calling a function, another function must be called. Of course, we may soon think of class constructors and member functions. In addition to this method,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn