Home >php教程 >php手册 >php 怎么确保两个函数被调用的顺序

php 怎么确保两个函数被调用的顺序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 10:46:41773browse

在php中,怎么确保在调用一个函数之前,必须调用另外一个函数。当然,我们很快可能想到类的构造函数及成员函数。除了这种方式之外,还有其他方式吗?

假设 在调用Search之前,必须调用Init函数,可以用如下方式组织代码:

[php] function Init(){ 
    //init自身的实现  
    // to do init  
 
 
    //Search 的实现      
    // to do search  
    function Search(){ 
    } 

function Init(){
 //init自身的实现
 // to do init


 //Search 的实现 
 // to do search
 function Search(){
 }
}


这样,在调用函数 Search的时候,必须先调用Init。否则,会报错!

其它详情,请参阅:http://cn2.php.net/manual/en/language.functions.php

 

摘自 心灵净土
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