本文介绍了PHP:如何避免重新声明函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我倾向于得到如下错误:
$ b
我怎样才能避免这个错误?是否有可能在声明它之前创建一个IF子句来检查函数是否被声明了?
$ b
_once code> include 和 require 将强制PHP检查文件是否已经包含/必需,如果是,则不是 include / 需要它,从而防止'无法重新声明x函数... '致命错误。
I tend to get errors such as:
how can I avoid the error? Is it possible to create a IF-clause to check whether a function is declared before declaring it?
解决方案
Use require_once or include_once as opposed to include or require when including the files that contain your functions.
The _once siblings of include and require will force PHP to check if the file has already been included/required, and if so, not include/require it again, thereby preventing 'cannot redeclare x function...' fatal errors.
这篇关于PHP:如何避免重新声明函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!