How does one go about debugging PHP?

Discussion in 'PHP' started by xarzu, Sep 3, 2013.

  1. #1
    How does one go about debugging PHP?

    I have an open source CMS php web site. The template / theme that I have has some issues. I have tried looking online for a solution along the expected and typical paths but they have reached a dead end.

    So I have decided to do it the hard way and actually get into the code and find the error

    Any suggestions on how I should begin?
     
    xarzu, Sep 3, 2013 IP
  2. cLogik

    cLogik Active Member

    Messages:
    159
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    90
    #2
    HELLo,

    If you have issues with the HTML / CSS, the your first step would be the inspector in Chrome / Safari. Right click the problem area and select "Inspect element" (Unsure if thats the exact phrase in english). This will open a new pane where you will see all the html / css, you can even edit the html / css directly in the inspector to see the changes live. (Tho, nothing is saved of course).

    This will at least give you a starting point at figuring out what HTML that goes wrong, and when you know that, you need to figure what PHP file that generates the problem html.

    Bit unsure if this is the answer to your question, but please do explain a bit more further if the above doesn't help :)
     
    cLogik, Sep 3, 2013 IP
  3. Active Build

    Active Build Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    Mozilla Firefox has that feature too.
     
    Active Build, Sep 3, 2013 IP
  4. topcoder

    topcoder Well-Known Member

    Messages:
    125
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    138
    #4
    You can use eclipse or php developer and step through the code
     
    topcoder, Sep 4, 2013 IP
  5. SadClown

    SadClown Member

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    33
    #5
    Are you positive they are PHP errors? Normally it will show some message in the DOM if there is an actual error in the PHP code. Otherwise, it may be just some HTML/CSS/Javascript issues. In that case, the Chrome developer console (ctrl + shift + j in Chrome) will tell you where those errors may be. The only other way I have debugged software was to dig into the code myself reading it manually and tweaking things related to the error to see if it changes anything.
     
    SadClown, Sep 10, 2013 IP
  6. xxxize

    xxxize Member

    Messages:
    33
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    38
    #6
    I recommend you from the firefox the firebug addon.
    You can change html and css on the fly.
    Also for php enable errors messages:

    ini_set('display_errors', '1');
    
    error_reporting (E_ALL); 
    PHP:
     
    xxxize, Sep 11, 2013 IP
  7. johannawilliams

    johannawilliams Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #7
    Place the following code in the start of the file to debug the PHP code:

    <?php
    ini_set('display_errors', 'On');
    error_reporting(E_ALL);
     
    johannawilliams, Sep 19, 2013 IP
  8. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #8
    fan of xdebug for profiling and can also use it for debuging and tracing
     
    themullet, Sep 19, 2013 IP