How to disable PHP cutting off parts of long arguments in exception stack trace?

后端 未结 2 1687
故里飘歌
故里飘歌 2020-12-30 03:55

Sometimes things like this happen:

#0 /some/path(1): Class_Name->exception_trigger()
#1 /some/other/path(5):  get_to(\'/some/long/path/tha...\')


        
相关标签:
2条回答
  • 2020-12-30 04:40

    You'll have to replace the uncaught exception handler. Example:

    function exception_handler($exception) {
        $i = 0;
        foreach ($exception->getTrace() as $frame) {
            echo sprintf("#%d %s(%d): %s(%s)\n",
                $i++, $frame["file"], $frame["line"],
                $frame["function"],
                implode(", ", array_map(
                    function ($e) { return var_export($e, true); }, $frame["args"])));
        }
    }
    
    set_exception_handler('exception_handler');
    

    Now you'll get something like:

    #0 /home/glopes/a.php(21): a('loooooooooooooooooooooooooooooooooong argument')
    #1 /home/glopes/a.php(24): b()
    
    0 讨论(0)
  • 2020-12-30 04:40

    If you're using xdebug you can specify the length and number of variables it spits out.

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