首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >PhpUnit没有显示php致命错误的堆栈跟踪

PhpUnit没有显示php致命错误的堆栈跟踪
EN

Stack Overflow用户
提问于 2011-05-14 00:10:04
回答 1查看 6K关注 0票数 20

PhpUnit目前没有显示代码中出现的错误的堆栈跟踪。

我如何配置它才能做到这一点呢?

EN

回答 1

Stack Overflow用户

发布于 2011-07-07 17:55:57

当php没有提供堆栈转储时,我发现这是一种很蹩脚但却很有效的方法。我在一个名为DebugUtil的类中有这个。

代码语言:javascript
复制
        /**
         * This is for use when you have the UBER-LAME...
         * "PHP Fatal error:  Maximum function nesting level of '100' reached,
         * aborting!  in Lame.php(1273)
         * ...which just craps out leaving you without a stack trace.
         * At the line in the file where it finally spazzes out add
         * something like...
         * DebugUtil::dumpStack('/tmp/lame');
         * It will write the stack into that file every time it passes that
         * point and when it eventually blows up (and probably long before) you
         * will be able to see where the problem really is.
         */
        public static function dumpStack($fileName)
        {
            $stack = "";
            foreach (debug_backtrace() as $trace)
            {
                if (isset($trace['file'])  &&
                    isset($trace['line'])  &&
                    isset($trace['class']) &&
                    isset($trace['function']))
                {
                    $stack .= $trace['file']     . '#' .
                              $trace['line']     . ':' .
                              $trace['class']    . '.' .
                              $trace['function'] . "\n";
                }
            }
            file_put_contents($fileName, $stack);
        }
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5994729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档