PHP:如何避免重新声明函数? [英] PHP: how to avoid redeclaring functions?

查看:153
本文介绍了PHP:如何避免重新声明函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我倾向于得到如下错误:
$ b


致命错误:无法重新声明get_raw_data_list()(以前在/ var / www /代码/处理程序/ make_a_thread / get_raw_data_list.php:7)在/var/www/codes/handlers/make_a_thread/get_raw_data_list.php on line 19




我怎样才能避免这个错误?是否有可能在声明它之前创建一个IF子句来检查函数是否被声明了?

使用 require_once include_once as反对 include require 包含您的函数的文件。


$ b

_once code> include 和 require 将强制PHP检查文件是否已经包含/必需,如果是,则不是 include / 需要它,从而防止'无法重新声明x函数... '致命错误。


I tend to get errors such as:

Fatal error: Cannot redeclare get_raw_data_list() (previously declared in /var/www/codes/handlers/make_a_thread/get_raw_data_list.php:7) in /var/www/codes/handlers/make_a_thread/get_raw_data_list.php on line 19

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:如何避免重新声明函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆