您现在的位置是:首页 > 一次调试TP3.2奇怪的include问题

一次调试TP3.2奇怪的include问题

默认 2020-10-11 00:00 1558人围观 来源:原创
tp  
简介在一次网站迁移过程中,发现同样是TP3.2的程序,一个能运行,另一个无法运行。

第一次尝试从nginx/php-fpm日志去分析问题,结果基本没什么有效信息,试了好多天也没有找到问题,页面白屏,只能看到是500错。

第二次尝试打开PHP的报错信息ini_set('display_errors','On');error_reporting(E_ALL); 结果只能看到Fatal error: Uncaught Error: Call to undefined function Think\C() in /www/ThinkPHP/Library/Think/Think.class.php:347 Stack trace: # 这个错误,百度了一番基本没有有效的答案。研究了半天发现是Think.class.php里面include Commons.php等文件失败,但是找不到失败的原因。因为这个错其实是因为include文件失败,导致C函数无法使用,并不是根源上引起无法访问的错误。

第三次尝试,突然发现Think.class.php里面有

// 设定错误和异常处理

register_shutdown_function('Think\Think::fatalError');

set_error_handler('Think\Think::appError');

set_exception_handler('Think\Think::appException');

这些代码,看上去是TP用自己的错误处理方法接管了PHP原生的,注释掉试试能不能得到更多错误。果然得到这样足够清楚的报错:

Warning: include(/www/ThinkPHP/Common/functions.php): failed to open stream: No such file or directory in //www/ThinkPHP/Library/Think/Think.class.php on line 56

Warning: include(): Failed opening '/www/ThinkPHP/Common/functions.php' for inclusion (include_path='.:/usr/share/php') in //www/ThinkPHP/Library/Think/Think.class.php on line 56
//www/ThinkPHP/Common/functions.php
Parse error: syntax error, unexpected 'public' (T_PUBLIC), expecting end of file in //www/ThinkPHP/Common/functions.php on line 1240

看起来是公共函数库里多了一个public关键字,应该是哪次加方法加错了。删掉public果然解决了这次的奇怪问题。

总结发现,原来因为修改TP核心库里面的公共函数库语法错,导致include该文件失败,进而导致C函数无法使用,坑就坑在这里,TP注册了异常处理方法,但是它异常处理方法里又要用到C函数,这样又掩盖了程序出错的信息,使其得不到展示。

 

 

 

我的博客即将同步至腾讯云开发者社区,邀请大家一同入驻:https://cloud.tencent.com/developer/support-plan?invite_code=3cn0udci9ym88

文章评论