Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a php.ini directive that enables stack traces on errors?

Tags:

php

Is there a php.ini directive that enables stack traces on errors? I already looked here: http://php.net/manual/en/ini.core.php. My shared-hosting does not have Xdebug installed for some reason. I tried putting these in .htaccess:

php_value track_erors On
php_value report_zend_debug 1

but no stack trace.

like image 807
Lawrence I. Siden Avatar asked Jan 22 '23 18:01

Lawrence I. Siden


1 Answers

There's debug_backtrace. This won't work for fatal errors though, since those cannot be handled.

Example:

<?php
function exceptions_error_handler($severity, $message, $filename, $lineno) { 
    var_dump(debug_backtrace());
}

set_error_handler('exceptions_error_handler');

function c() {
echo $a;
}

c();

gives:

array
  0 => 
    array
      'file' => string '/tmp/cpu7HL5A' (length=13)
      'line' => int 9
      'function' => string 'exceptions_error_handler' (length=24)
      'args' => 
        array
          0 => &int 8
          1 => &string 'Undefined variable: a' (length=21)
          2 => &string '/tmp/cpu7HL5A' (length=13)
          3 => &int 9
          4 => &
            array
              empty
  1 => 
    array
      'file' => string '/tmp/cpu7HL5A' (length=13)
      'line' => int 12
      'function' => string 'c' (length=1)
      'args' => 
        array
          empty
like image 160
Artefacto Avatar answered Jan 25 '23 23:01

Artefacto