If you find Xdebug useful, please consider supporting the project.

Basic Features

Xdebug's basic functions include the display of stack traces on error conditions, maximum nesting level protection and time tracking.

Related Settings


boolean xdebug.default_enable = true

If this setting is 1, then stacktraces will be shown by default on an error event. You can disable showing stacktraces from your code with xdebug_disable(). As this is one of the basic functions of Xdebug, it is advisable to leave this setting set to 1.


integer xdebug.force_display_errors = 0

Introduced in Xdebug >= 2.3

If this setting is set to 1 then errors will always be displayed, no matter what the setting of PHP's display_errors is.


integer xdebug.force_error_reporting = 0

Introduced in Xdebug >= 2.3

This setting is a bitmask, like error_reporting. This bitmask will be logically ORed with the bitmask represented by error_reporting to dermine which errors should be displayed. This setting can only be made in php.ini and allows you to force certain errors from being shown no matter what an application does with ini_set().


integer xdebug.halt_level = 0

Introduced in Xdebug >= 2.3

This setting allows you to configure a mask that determines whether, and which, notices and/or warnings get converted to errors. You can configure notices and warnings that are generated by PHP, and notices and warnings that you generate yourself (by means of trigger_error()). For example, to convert the warning of strlen() (without arguments) to an error, you would do:

ini_set('xdebug.halt_level', E_WARNING);
strlen();
echo "Hi!\n";

Which will then result in the showing of the error message, and the abortion of the script. echo "Hi!\n"; will not be executed.

The setting is a bit mask, so to convert all notices and warnings into errors for all applications, you can set this in php.ini:

xdebug.halt_level=E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE

The bitmask only supports the four level that are mentioned above.


integer xdebug.max_nesting_level = 256

Controls the protection mechanism for infinite recursion protection. The value of this setting is the maximum level of nested functions that are allowed before the script will be aborted.

Before Xdebug 2.6, this would create a fatal exception if exceeded. From Xdebug 2.6 and later, an "Error" exception is thrown instead.

Before Xdebug 2.3, the default value was 100.


integer xdebug.max_stack_frames = -1

Introduced in Xdebug >= 2.3

Controls how many stack frames are shown in stack traces, both on the command line during PHP error stack traces, as well as in the browser for HTML traces.


boolean xdebug.scream = false

Introduced in Xdebug >= 2.1

If this setting is 1, then Xdebug will disable the @ (shut-up) operator so that notices, warnings and errors are no longer hidden.

Related Functions


xdebug_call_class( int $depth = 2 ) : mixed

Returns the calling class

This function returns the name of the class that defined the current method, NULL if the stack frame does not exist, or FALSE if no class is associated with this call.

Example:

<?php
class Strings
{
    static function 
fix_string($a)
    {
        echo
            
xdebug_call_class().
            
"::".
            
xdebug_call_function().
            
" is called at ".
            
xdebug_call_file().
            
":".
            
xdebug_call_line();
    }
}

$ret Strings::fix_string'Derick' );
?>

Returns:

Called @ /home/httpd/html/test/xdebug_caller.php:17 from ::{main}

To retrieve information from earlier stack frames, use the optional $depth argument. A value of 1 returns the call information of the method that executed xdebug_call_class():

Example:

<?php
class Strings
{
    static function 
fix_string$a )
    {
        echo
            
xdebug_call_class).
            
"::".
            
xdebug_call_function).
            
" is called at ".
            
xdebug_call_file).
            
":".
            
xdebug_call_line);
    }
}

$ret Strings::fix_string'Derick' );
?>

Returns:

Strings::fix_string is called at /home/httpd/html/test/xdebug_caller:17

A value of 2 (the default) returns the call information of the "grand parent" of the current method:

Example:

<?php
class Strings
{
    static function 
fix_string$a )
    {
        echo
            
xdebug_call_class).
            
"::".
            
xdebug_call_function).
            
" is called at ".
            
xdebug_call_file).
            
":".
            
xdebug_call_line);
    }

    static function 
fix_strings( array $a )
    {
        foreach ( 
$a as $element )
        {
            
self::fix_string$a );
        }
    }
}

$ret Strings::fix_strings( [ 'Derick' ] );
?>

Returns:

Strings::fix_strings is called at /home/httpd/html/test/xdebug_caller:25

A value of 0 returns the call information of the call to corresponding xdebug_call_* method:

Example:

<?php
class Strings
{
    static function 
fix_string$a )
    {
        echo
            
xdebug_call_class).
            
"::".
            
xdebug_call_function).
            
" is called at ".
            
xdebug_call_file).
            
":".
            
xdebug_call_line);
    }

    static function 
fix_strings( array $a )
    {
        foreach ( 
$a as $element )
        {
            
self::fix_string$a );
        }
    }
}

$ret Strings::fix_strings( [ 'Derick' ] );
?>

Returns:

::xdebug_call_function is called at /home/httpd/html/test/xdebug_caller:13

xdebug_call_file( int $depth = 2 ) : mixed

Returns the calling file

This function returns the filename from where the current function/method was executed from, or NULL if the stack frame does not exist

To retrieve information from earlier stack frames, use the optional $depth argument.

For examples and more extensive information, see xdebug_call_class().


xdebug_call_function( int $depth = 2 ) : mixed

Returns the calling function/method

This function returns the name of the current function/method, NULL if the stack frame does not exist, or FALSE if the stack frame has no function/method information

To retrieve information from earlier stack frames, use the optional $depth argument.

For examples and more extensive information, see xdebug_call_class().


xdebug_call_line( int $depth = 2 ) : mixed

Returns the calling line number

This function returns the line number from where the current function/method was called from, or NULL if the stack frame does not exist

To retrieve information from earlier stack frames, use the optional $depth argument.

For examples and more extensive information, see xdebug_call_class().


xdebug_dump_superglobals() : void

Displays information about super globals

This function dumps the values of the elements of the super globals as specified with the xdebug.dump.* php.ini settings. For the example below the settings in php.ini are:

Example:

xdebug.dump.GET=*
xdebug.dump.SERVER=REMOTE_ADDR

Query string:
?var=fourty%20two&array[a]=a&array[9]=b

Returns:

Dump $_SERVER
$_SERVER['REMOTE_ADDR'] =
string '127.0.0.1' (length=9)
Dump $_GET
$_GET['var'] =
string 'fourty two' (length=10)
$_GET['array'] =
array
  'a' => string 'a' (length=1)
  9 => string 'b' (length=1)

xdebug_get_collected_errors( bool $emptyList = false ) : array

Returns all collected error messages

This function returns all errors from the collection buffer that contains all errors that were stored there when error collection was started with xdebug_start_error_collection().

By default this function will not clear the error collection buffer. If you pass true as argument to this function then the buffer will be cleared as well.

This function returns a string containing all collected errors formatted as an "Xdebug table".


xdebug_get_function_count() : int

Returns the number of functions that have been called

This function returns the number of functions that have been called so far, including this function itself.


xdebug_get_headers() : array

Returns all the headers as set by calls to PHP's header() function

Returns all the headers that are set with PHP's header() function, or any other header set internally within PHP (such as through setcookie()), as an array.

Example:

<?php
header
"X-Test""Testing" );
setcookie"TestCookie""test-value" );
var_dumpxdebug_get_headers() );
?>

Returns:

array(2) {
  [0]=>
  string(6) "X-Test"
  [1]=>
  string(33) "Set-Cookie: TestCookie=test-value"
}

xdebug_memory_usage() : int

Returns the current memory usage

Returns the current amount of memory the script uses. Before PHP 5.2.1, this only works if PHP is compiled with --enable-memory-limit. From PHP 5.2.1 and later this function is always available.


xdebug_peak_memory_usage() : int

Returns the peak memory usage

Returns the maximum amount of memory the script used until now. Before PHP 5.2.1, this only works if PHP is compiled with --enable-memory-limit. From PHP 5.2.1 and later this function is always available.


xdebug_start_error_collection() : void

Starts recording all notices, warnings and errors and prevents their display

When this function is executed, Xdebug will cause PHP not to display any notices, warnings or errors. Instead, they are formatted according to Xdebug's normal error formatting rules (ie, the error table with the red exclamation mark) and then stored in a buffer. This will continue until you call xdebug_stop_error_collection().

This buffer's contents can be retrieved by calling xdebug_get_collected_errors() and then subsequently displayed. This is really useful if you want to prevent Xdebug's powerful error reporting features from destroying your layout.


xdebug_stop_error_collection() : void

Stops recording of all notices, warnings and errors as started by xdebug_start_error_collection()

When this function is executed, error collection as started by xdebug_start_error_collection() is aborted. The errors stored in the collection buffer are not deleted and still available to be fetched through xdebug_get_collected_errors().


xdebug_time_index() : float

Returns the current time index

Returns the current time index since the starting of the script in seconds.

Example:

<?php
echo xdebug_time_index(), "\n";
for (
$i 0$i 250000$i++)
{
    
// do nothing
}
echo 
xdebug_time_index(), "\n";
?>

Returns:

0.00038003921508789
0.76580691337585