How to print a debug log?

前端 未结 15 1825
北海茫月
北海茫月 2020-12-12 10:07

I\'d like to debug some PHP code, but I guess printing a log to screen or file is fine for me.

How should I print a log in PHP code?

The u

15条回答
  •  执念已碎
    2020-12-12 10:22

    Are you debugging on console? There are various options for debugging PHP. The most common function used for quick & dirty debugging is var_dump.

    That being said and out of the way, although var_dump is awesome and a lot of people do everything with just that, there are other tools and techniques that can spice it up a bit.

    Things to help out if debugging in a webpage, wrap

     
    tags around your dump statement to give you proper formatting on arrays and objects.

    Ie:

    some html code .... some link to test
    dump $tpl like this:

    And, last but not least make sure if debugging your error handling is set to display errors. Adding this at the top of your script may be needed if you cannot access server configuration to do so.

    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    

    Good luck!

提交回复
热议问题