#1
  1. A Change of Season
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    2,675
    Rep Power
    171

    How to debug PHP code


    1 - Why doesn't the code below show something like "Something" error" (because of missing bracket)? Why does it show blank page?
    2 - What is the best way to debug php code?
    3 - How many types of php errors are there? Ie, synthax, fatal,...
    4 - How many types of error reporting are there?
    PHP Code:
    error_reporting(E_ALL);
    ini_set('display_errors''1');

    if(!isset(
    $_POST['request_sent']){
    echo 
    "Not Post";

  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by zxcvbnm
    1 - Why doesn't the code below show something like "Something" error" (because of missing bracket)? Why does it show blank page?
    Setting display_errors at runtime has no effect on parse errors in this script, because the errors happen before the script is even executed.



    Originally Posted by zxcvbnm
    2 - What is the best way to debug php code?
    For professional debugging, check Xdebug.

    And of course there's the good old var_dump().



    Originally Posted by zxcvbnm
    3 - How many types of php errors are there? Ie, synthax, fatal,...
    http://php.net/manual/en/errorfunc.constants.php



    Originally Posted by zxcvbnm
    4 - How many types of error reporting are there?
    You can combine any of the error constants in the link above in order to include or exclude the errors you want.

    Check the second link in my signature, it might be interesting for you.
    Last edited by Jacques1; March 28th, 2013 at 08:21 PM.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    You have to enable errors in php.ini to see parse errors.

    You can also detect parse errors by running your code through php -l on the command line.

    [someuser #] php -l filename.php
    PHP Fatal Error: Unexpected '{' in filename.php on line 4.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo