How to debug Php code?

前端 未结 10 1875
臣服心动
臣服心动 2020-12-08 03:20

I am newbie on PHP. Here is my situation. I write my code in vim and put it under /var/www/ then I can use

localhost/*.php

相关标签:
10条回答
  • 2020-12-08 03:35

    include this both line in code to see what kind of error is.

    <?php 
           ini_set("display_errors",1);
           error_reporting(E_ALL);
            //code goes here
    ?>
    
    0 讨论(0)
  • 2020-12-08 03:35

    You can check the log file output by PHP. A good way to see your configuration is to use phpinfo().

    Also you can set error_reporting() so you can see the error message instead of a white page.

    0 讨论(0)
  • 2020-12-08 03:44

    PHP produces an error_log file in its directory whenever a problem occurs, you can find debug information there.

    Also, try using var_dump($someVarible). This will give you useful information about the current state of a variable - often better than echo.

    0 讨论(0)
  • 2020-12-08 03:45

    Use these two lines to debug (this will enable to find the errors on the line numbers):

    ini_set('display_errors', 'On');
    error_reporting(E_ALL | E_STRICT);
    
    0 讨论(0)
  • 2020-12-08 03:49

    In most cases, if you set you error_reportto -1 you'll be able to see all notices, warning and errors in your browser.

    0 讨论(0)
  • 2020-12-08 03:51

    If on a localhost, I would suggest using firefox or chrome and installing firebug for mozilla, and chrome gets a default. Be sure that on a local host your settings are matched to the server you are uploading to as this can cause problems when going live.

    Specifically most shared hosting has PHP on safe mode and output buffering off, so if you use it, use it by calling it by calling ob_start(); etc, otherwise you should have no problems, and learning to debug is part of the fun, helps you learn alot :)

    As for php errors just re-edit your php.ini file, you can find al relevant information on http://php.net

    Happy Coding

    0 讨论(0)
提交回复
热议问题