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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:46:41
Original
771 people have browsed it

在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

 

摘自 心灵净土
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template