Is there a Pretty Print Stack Dump?

后端 未结 8 1978
半阙折子戏
半阙折子戏 2021-02-07 17:41

Let\'s face it, debug_backtrace() output is not very pretty. Did anyone code a wrapper?

And what\'s your favourite pretty var_dump() (which is

8条回答
  •  半阙折子戏
    2021-02-07 18:05

    You also have kint (github repo) which has a composer package on the packagist repository

    So either download the library manually or with composer, it's just a matter of :

    $ composer init
    $ composer require raveren/kint
    $ composer install
    

    Then, instead of ini_set('display_errors', 'On');, I prefer to use this simple handler in my main (first) include file :

    if (  getenv('__project_env__') === 'DEV') {
    
      error_reporting(E_ALL | E_STRICT);
    
      function shutdown_handler() {
        $error = error_get_last();
        Kint::trace();
        Kint::dump($error);
      }
      register_shutdown_function('shutdown_handler');
    
    } else {
     ...
    }
    

    With __project_env__ being set in Apache's Virtualhost (SetEnv __project_env__ "DEV") so as not to pollute the different branches of the git repository where the project lives with configuration items which are by essence environmental

    • In DEV : i get my debugging
    • In PROD, it's silent by default

    Here is a screenshot of how the trace looks (each step is collapsible):


    (source: github.io)

提交回复
热议问题