• 使用Xdebug调试和优化PHP程序[2]


    作者:Haohappy     

    MSN: haohappy at msn.com

    Blog: http://blog.csdn.net/haohappy2004

    2006-07-04

    Go on..现在我们来从最简单的程序调试开始一步步介绍Xdebug。

    调试:

    我们先写一个可以导致执行出错的程序,例如尝试包含一个不存在的文件。

    testXdebug.php

     

    <?php

    require_once(‘abc.php’);

    ?>

     

    然后通过浏览器访问,我们惊奇地发现,出错信息变成了彩色的了:

     

    不过除了样式改变,和我们平时打印的出错信息内容没什么不同,意义不大。好,我们继续改写程序:

     

    testXdebug2.php

     

    <?php

    testXdebug();

    function testXdebug() {

           require_once('abc.php');

    }

    ?>

     

    输出信息:

     

    发现了什么? Xdebug跟踪代码的执行,找到了出错的函数testXdebug()

     

    我们把代码再写得复杂一些: 

    testXdebug3.php

    <?php

    testXdebug();

    function testXdebug() {

           requireFile();    

    }

    function requireFile() {

           require_once('abc.php');

    }

    ?>

    输出信息:

    呵呵,也就是说Xdebug具有类似于JavaException的“跟踪回溯”的功能,可以根据程序的执行一步步跟踪到出错的具体位置,哪怕程序中的调用很复杂,我们也可以通过这个功能来理清代码关系,迅速定位,快速排错。

  • 相关阅读:
    find-the-distance-from-a-3d-point-to-a-line-segment
    Distance Point to Line Segment
    Shortest distance between a point and a line segment
    Splitting and Merging--区域分裂与合并算法
    手写区域分裂合并算法
    free online editor
    SQL server ide
    online c++ compiler
    online sql editor
    Web-based SQL editor
  • 原文地址:https://www.cnblogs.com/cnsanshao/p/2152839.html
Copyright © 2020-2023  润新知