GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing xdebug.org — Xdebug: Documentation » All functions Documentation - all functionsThis section describes all available functions available in Xdebug. var_dump( mixed ...$var ) : void #Displays detailed information about a variable This function is overloaded by Xdebug, see the description for xdebug_var_dump(). xdebug_break() : bool #Emits a breakpoint to the debug client This function makes the debugger break on the line it is called from, as if a normal file/line breakpoint was set on this line through the debugger protocol.
If no debugging session is active yet, and xdebug.start_with_request is set to
The function returns xdebug_call_class( int $depth = 2 ) : mixed #Returns the calling class
This function returns the name of the class that defined the current method,
Example:Returns:Called @ /home/httpd/html/test/xdebug_caller.php:17 from ::{main}
To retrieve information from earlier stack frames, use the optional
Example:Returns:Strings::fix_string is called at /home/httpd/html/test/xdebug_caller:17
A value of Example:Returns:Strings::fix_strings is called at /home/httpd/html/test/xdebug_caller:25
A value of Example: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
To retrieve information from earlier stack frames, use the optional
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,
To retrieve information from earlier stack frames, use the optional
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
To retrieve information from earlier stack frames, use the optional
For examples and more extensive information, see xdebug_call_class(). xdebug_code_coverage_started() : bool #Returns whether code coverage is active Returns whether code coverage has been started. Example:Returns:bool(false) bool(true) xdebug_connect_to_client() : bool #Instructs Xdebug to establish a debugging session Introduced in version 3.1
This functions instructs Xdebug to try to establish a connection to a debugging client. Normally, Xdebug tries to start a debugging session at the start of the request. If a debugging client is not listening at that point, then Xdebug does not try to re-establish a connection during the remainder of the request. In the situation where one long running PHP process handles multiple tasks, perhaps from a queue, calling xdebug_connect_to_client() can then be used to re-try to establish a connection for a specific worker job. xdebug_debug_zval( string ...$varname ) : void #Displays information about a variable This function displays structured information about one or more variables that includes its type, value and refcount information. Arrays are explored recursively with values. This function is implemented differently from PHP's debug_zval_dump() function in order to work around the problems that that function has because the variable itself is actually passed to the function. Xdebug's version is better as it uses the variable name to lookup the variable in the internal symbol table and accesses all the properties directly without having to deal with actually passing a variable to a function. The result is that the information that this function returns is much more accurate than PHP's own function for showing zval information. Support for anything but simple variable names (such as "a[2]" below) is supported since Xdebug 2.3. Example:Returns:a: (refcount=2, is_ref=1)=array ( 0 => (refcount=1, is_ref=0)=1, 1 => (refcount=1, is_ref=0)=2, 2 => (refcount=2, is_ref=1)=3) a[2]: (refcount=2, is_ref=1)=3 xdebug_debug_zval_stdout( string ...$varname ) : void #Returns information about variables to stdout This function displays structured information about one or more variables that includes its type, value and refcount information. Arrays are explored recursively with values. The difference with xdebug_debug_zval() is that the information is not displayed through a web server API layer, but directly shown on stdout (so that when you run it with Apache in single process mode it ends up on the console). Example:Returns:a: (refcount=2, is_ref=1)=array ( 0 => (refcount=1, is_ref=0)=1, 1 => (refcount=1, is_ref=0)=2, 2 => (refcount=2, is_ref=1)=3) 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:Returns:
xdebug_get_code_coverage() : array #Returns code coverage information Returns a structure which contains information about which lines were executed in your script (including include files). The following example shows code coverage for one specific file: Example:Returns:array
'/home/httpd/html/test/xdebug/docs/xdebug_get_code_coverage.php' =>
array (size=11)
5 => int 1
6 => int -2
7 => int -2
10 => int 1
11 => int -1
13 => int 1
14 => int 1
16 => int 1
18 => int 1
19 => int 1
21 => int 1The information that is collected consists of an two dimensional array with as primary index the executed filename and as secondary key the line number. The value in the elements represents whether the line has been executed or whether it has unreachable lines. The returned values for each line are:
-1 is only returned when the XDEBUG_CC_UNUSED
is enabled and value -2 is only returned when both
XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE are enabled
when starting Code Coverage Analysis through xdebug_start_code_coverage().
If path and branch checking has been enabled with the
The following example illustrates that. Example:Returns:array (size=1)
'/tmp/foo2.php' =>
array (size=2)
'lines' =>
array (size=5)
5 => int 1
6 => int 1
8 => int 1
10 => int 1
12 => int 1
'functions' =>
array (size=1)
'c' =>
array (size=2)
'branches' =>
array (size=4)
0 =>
array (size=7)
'op_start' => int 0
'op_end' => int 4
'line_start' => int 4
'line_end' => int 5
'hit' => int 1
'out' =>
array (size=1)
0 => int 9
'out_hit' =>
array (size=1)
0 => int 1
5 =>
array (size=7)
'op_start' => int 5
'op_end' => int 8
'line_start' => int 6
'line_end' => int 5
'hit' => int 1
'out' =>
array (size=1)
0 => int 9
'out_hit' =>
array (size=1)
0 => int 1
9 =>
array (size=7)
'op_start' => int 9
'op_end' => int 11
'line_start' => int 5
'line_end' => int 5
'hit' => int 1
'out' =>
array (size=2)
0 => int 12
1 => int 5
'out_hit' =>
array (size=2)
0 => int 1
1 => int 1
12 =>
array (size=7)
'op_start' => int 12
'op_end' => int 13
'line_start' => int 8
'line_end' => int 8
'hit' => int 1
'out' =>
array (size=1)
0 => int 2147483645
'out_hit' =>
array (size=1)
0 => int 0
'paths' =>
array (size=2)
0 =>
array (size=2)
'path' =>
array (size=3)
0 => int 0
1 => int 9
2 => int 12
'hit' => int 0
1 =>
array (size=2)
'path' =>
array (size=5)
0 => int 0
1 => int 9
2 => int 5
3 => int 9
4 => int 12
'hit' => int 1
Inside each function the Returns:9 =>
array (size=7)
'op_start' => int 9
'op_end' => int 11
'line_start' => int 5
'line_end' => int 5
'hit' => int 1
'out' =>
array (size=2)
0 => int 12
1 => int 5
'out_hit' =>
array (size=2)
0 => int 1
1 => int 1The index is the starting opcode, and the fields mean:
Each function also contains a Returns:1 =>
array (size=2)
'path' =>
array (size=5)
0 => int 0
1 => int 9
2 => int 5
3 => int 9
4 => int 12
'hit' => int 1The index is a normal PHP array index, and the fields mean:
The Xdebug source contains a
file
containing a Returns:c - branches - 00; OP: 00-04; line: 06-07 HIT; out1: 09 HIT - 05; OP: 05-08; line: 08-07 HIT; out1: 09 HIT - 09; OP: 09-11; line: 07-07 HIT; out1: 12 HIT; out2: 05 HIT - 12; OP: 12-13; line: 10-10 HIT; out1: EX X - paths - 0 9 12: X - 0 9 5 9 12: HIT
The function also generates a file Example:This generates an image where a solid line means that the path has been followed, and a dashed line means that that path has not been followed.
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
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_function_stack( array $options = [] ) : array #Returns information about the stack Returns an array which resembles the stack trace up to this point. The example script: Example:Returns:array (size=3)
0 =>
array (size=6)
'time' => float 2.648155248
'memory' => int 530520
'function' => string '{main}' (length=6)
'file' => string 'Standard input code' (length=19)
'line' => int 0
'params' =>
array (size=0)
empty
1 =>
array (size=8)
'time' => float 2.648221973
'memory' => int 530664
'function' => string 'fix_strings' (length=11)
'type' => string 'dynamic' (length=7)
'class' => string 'strings' (length=7)
'file' => string 'Standard input code' (length=19)
'line' => int 16
'params' =>
array (size=1)
'b' => string '[0 => 'Derick']' (length=15)
2 =>
array (size=8)
'time' => float 2.648243513
'memory' => int 530664
'function' => string 'fix_string' (length=10)
'type' => string 'dynamic' (length=7)
'class' => string 'strings' (length=7)
'file' => string 'Standard input code' (length=19)
'line' => int 10
'params' =>
array (size=1)
'a' => string ''Derick'' (length=8)
Through the $options['local_vars'] #
If you set the Example:Returns:array (size=3)
0 =>
array (size=7)
'time' => float 4.507993828
'memory' => int 586272
'function' => string '{main}' (length=6)
'file' => string 'Standard input code' (length=19)
'line' => int 0
'params' =>
array (size=0)
empty
'variables' =>
array (size=2)
's' =>
object(strings)[1]
'ret' => null
1 =>
array (size=9)
'time' => float 4.508039954
'memory' => int 586416
'function' => string 'fix_strings' (length=11)
'type' => string 'dynamic' (length=7)
'class' => string 'strings' (length=7)
'file' => string 'Standard input code' (length=19)
'line' => int 16
'params' =>
array (size=1)
'b' => string '[0 => 'Derick']' (length=15)
'variables' =>
array (size=2)
'b' =>
array (size=1)
...
'item' => string 'Derick' (length=6)
2 =>
array (size=9)
'time' => float 4.508065061
'memory' => int 586416
'function' => string 'fix_string' (length=10)
'type' => string 'dynamic' (length=7)
'class' => string 'strings' (length=7)
'file' => string 'Standard input code' (length=19)
'line' => int 10
'params' =>
array (size=1)
'a' => string ''Derick'' (length=8)
'variables' =>
array (size=1)
'a' => string 'Derick' (length=6)
The values in the $options['params_as_values'] #
You can changes these to also be values by setting the Example:Returns:array (size=3)
0 =>
array (size=6)
'time' => float 5.128140207
'memory' => int 589968
'function' => string '{main}' (length=6)
'file' => string 'Standard input code' (length=19)
'line' => int 0
'params' =>
array (size=0)
empty
1 =>
array (size=8)
'time' => float 5.128188808
'memory' => int 590112
'function' => string 'fix_strings' (length=11)
'type' => string 'dynamic' (length=7)
'class' => string 'strings' (length=7)
'file' => string 'Standard input code' (length=19)
'line' => int 16
'params' =>
array (size=1)
'b' =>
array (size=1)
...
2 =>
array (size=8)
'time' => float 5.128214727
'memory' => int 590112
'function' => string 'fix_string' (length=10)
'type' => string 'dynamic' (length=7)
'class' => string 'strings' (length=7)
'file' => string 'Standard input code' (length=19)
'line' => int 10
'params' =>
array (size=1)
'a' => string 'Derick' (length=6)$options['from_exception'] #
The last option is This should be used in a user-defined exception handler. Example:Returns:array (size=3)
0 =>
array (size=7)
'time' => float 5.194523655
'memory' => int 595976
'function' => string '{main}' (length=6)
'file' => string 'Standard input code' (length=19)
'line' => int 0
'params' =>
array (size=0)
empty
'variables' =>
array (size=1)
'e' => null
1 =>
array (size=9)
'time' => float 5.194572727
'memory' => int 596440
'function' => string '__construct' (length=11)
'type' => string 'dynamic' (length=7)
'class' => string 'Error_Entry' (length=11)
'file' => string 'Standard input code' (length=19)
'line' => int 38
'params' =>
array (size=2)
'base' => int 1
'errno' => int 2
'variables' =>
array (size=3)
'base' => int 1
'errno' => int 2
'return' => null
2 =>
array (size=9)
'time' => float 5.194576134
'memory' => int 596440
'function' => string 'newError' (length=8)
'type' => string 'static' (length=6)
'class' => string 'Error_Class' (length=11)
'file' => string 'Standard input code' (length=19)
'line' => int 33
'params' =>
array (size=1)
'errno' => boolean true
'variables' =>
array (size=3)
'errno' => boolean true
'elephpant' =>
object(Elephpant)[2]
...
'randoVar' => int 42
The stack trace you get when using xdebug_get_gc_run_count() : int #Returns the number of garbage collection runs that have been triggered so far The function returns the number of times the garbage collection has been triggered in the currently running script.
This number is available even if the xdebug.start_with_request INI setting is
not set to xdebug_get_gc_total_collected_roots() : int #Returns the number of variable roots that have been collected so far The function returns the number of variable roots that the garbage collection has collected during all runs of the garbage collector in the current script.
This number is available even if the xdebug.start_with_request INI setting is
not set to xdebug_get_gcstats_filename() : mixed #Returns the garbage collection statistics filename
Returns the name of the file which is used to save garbage collection
information to, or 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:Returns:array(2) {
[0]=>
string(6) "X-Test"
[1]=>
string(33) "Set-Cookie: TestCookie=test-value"
}xdebug_get_monitored_functions() : array #Returns information about monitored functions Returns a structure which contains information about where the monitored functions were executed in your script. The following example shows how to use this, and the returned information: Example:Returns:/tmp/monitor-example.php:10:
array(2) {
[0] =>
array(3) {
'function' =>
string(6) "strrev"
'filename' =>
string(24) "/tmp/monitor-example.php"
'lineno' =>
int(6)
}
[1] =>
array(3) {
'function' =>
string(6) "strrev"
'filename' =>
string(24) "/tmp/monitor-example.php"
'lineno' =>
int(8)
}
}xdebug_get_profiler_filename() : mixed #Returns the profile information filename
Returns the name of the file which is used to save profile information to, or
xdebug_get_stack_depth() : int #Returns the current stack depth level Returns the stack depth level. The main body of a script is level 0 and each include and/or function call adds one to the stack depth level. xdebug_get_tracefile_name() : false|string #Returns the name of the function trace file
Returns the name of the file which is used to trace the output of this
script to, or xdebug_info( ?string $category = null ) : mixed #Show and retrieve diagnostic information This function presents APIs to retrieve information about Xdebug itself. Which information gets returned, or displayed, depends on which arguments, or none at all, are given.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ( ! ) Xdebug: Your own message in /home/httpd/html/test/xdebug/print_function_stack.php on line 5 | ||||
|---|---|---|---|---|
| Call Stack | ||||
| # | Time | Memory | Function | Location |
| 1 | 0.0006 | 653896 | {main}( ) | ../print_function_stack.php:0 |
| 2 | 0.0007 | 654616 | foo( 42, 3141592654 ) | ../print_function_stack.php:7 |
| 3 | 0.0007 | 654736 | xdebug_print_function_stack ( 'Your own message' ) | ../print_function_stack.php:5 |
The bitmask "options" allows you to configure a few extra options. The following options are currently supported:
XDEBUG_STACK_NO_DESCxdebug_print_function_stack() was called from.Set filter
This function configures a filter that Xdebug employs when displaying stack traces or recording function traces, or when gathering code coverage. Filter configurations are applied to each execution unit (function, method, script body) independently.
The first argument, $group selects for which feature you want to
set up a filter. Currently there are two groups:
There are different kinds of filters that you can set. You can filter on either file path prefix, or fully qualified class name prefix (i.e. namespace). For each filter type you can a list of paths/namespaces to include or exclude. All matches are done in a case-insensitive way.
The XDEBUG_FILTER_CODE_COVERAGE group only supports
XDEBUG_PATH_INCLUDE, XDEBUG_PATH_EXCLUDE, and
XDEBUG_FILTER_NONE. All matches are done in a case-insensitive
way.
The constants to use as second "$list_type" argument are:
Configures a list of file paths to include. An execution unit is
included in the output if its file path is prefixed by any of the prefixes in
the array passed as third $configuration argument.
Please
note that a prefix of /home/derick would also match files in
/home/derickrethans, so it is recommended that you add the
trailing slash to the prefix in order to prevent this.
Sets up a list of paths to exclude. An execution unit will be excluded
from the output if its file path is prefixed by any of the prefixes from the
$configuration array.
Configures a list of class name prefixes to include. An execution unit is included in
the output if the class name, after namespace expansion, matches one of the
prefixes in the $configuration array. An empty string value is
special, and means functions that do not belong to a class. These are either
user-defined, or built-in PHP functions (e.g. strlen()).
Name space expansion happens automatically in PHP, and its engine will
always see the full qualified class name. In the code below, the
fully qualified class name DramIO\Whisky:
<?php
namespace DramIO;
class Whisky {
}
In order to match for all clases within a namespace, it is recommended to specify the prefix with the namespace separator
$configuration
array.$group.
It is not possible to configure a filter for paths/namespaces at the same time,
and neither is it possible to configure which paths to exclude and include at
the same time. Only one of the four list types can be active at any one time.
It is possible however, to turn off the filter altogether by using
XDEBUG_FILTER_NONE.
To exclude all files in the vendor sub-directory in traces:
<?php
xdebug_set_filter( XDEBUG_FILTER_TRACING, XDEBUG_PATH_EXCLUDE, [ __DIR__ . "/vendor/" ] );
?>
To include only function calls (without class name), and methods calls for the
ezc and DramIO\ classes in traces:
<?php
xdebug_set_filter( XDEBUG_FILTER_TRACING, XDEBUG_NAMESPACE_INCLUDE, [ "", "ezc", "DramIO\\" ] );
?>
To only perform code-coverage analysis for files in the src sub-directory:
<?php
xdebug_set_filter( XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_PATH_INCLUDE, [ __DIR__ . "/src/" ] );
?>Starts code coverage
This function starts gathering the information for code coverage. The information can be retrieved with the xdebug_get_code_coverage() function.
This function has three options, which act as a bitfield:
You can use the options as shown in the following example.
<?php
xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
?>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.
Starts function monitoring
This function starts the monitoring of functions that were given in a list as argument to this function. Function monitoring allows you to find out where in your code the functions that you provided as argument are called from. This can be used to track where old, or, discouraged functions are used.
<?php
xdebug_start_function_monitor( [ 'strrev', 'array_push' ] );
?>You can also add class methods and static methods to the array that defines which functions to monitor. For example, to catch static calls to DramModel::canSee and dynamic calls to Whisky->drink, you would start the monitor with:
<?php
xdebug_start_function_monitor( [ 'DramModel::canSee', 'Whisky->drink'] );
?>The defined functions are case sensitive, and a dynamic call to a static method will not be caught.
Start the collection of garbage collection statistics
Start tracing garbage collection attempts from this point to the file in the gcstatsFile parameter. If no filename is given, then garbage collection stats file will be placed in the directory as configured by the xdebug.output_dir setting.
In case a file name is given as first parameter, the name is relative to the current working directory. This current working directory might be different than you expect it to be, so please use an absolute path in case you specify a file name. Use the PHP function getcwd() to figure out what the current working directory is.
If xdebug.start_with_request=yes, then filename depends on the
xdebug.gc_stats_output_name setting.
The full path and filename to which Xdebug collects statistics into is returned from this function. This will be either the filename you pass in, or the auto generated filename if no filename has been passed in.
Starts a new function trace
Start tracing function calls from this point to the file in the
$trace_file parameter. If no filename is given, then the trace file will
be placed in the directory as configured by the xdebug.output_dir setting.
In case a file name is given as first parameter, the name is relative to the current working directory. This current working directory might be different than you expect it to be, so please use an absolute path in case you specify a file name. Use the PHP function getcwd() to figure out what the current working directory is.
The name of the trace file is {$trace_file}.xt. If the trace was started at
the beginning of the request because xdebug.start_with_request is set to
yes, then the filename depends on the
xdebug.trace_output_name setting.
The options parameter is a bitfield; currently there are four options:
.xt is
not added automatically to the end of trace file names.
The XDEBUG_TRACE_FLAMEGRAPH_COST and
XDEBUG_TRACE_FLAMEGRAPH_MEM flags are used to create flame graph
data. Flame Graphs are described separately.
<?php
xdebug_start_trace("/tmp/xdebug.trace", XDEBUG_TRACE_COMPUTERIZED|XDEBUG_TRACE_NAKED_FILENAME);
?>
The line above creates a file named /tmp/xdebug.trace.
It does not add .xt to the end of the filename (due to
XDEBUG_TRACE_NAKED_FILENAME).
The tab-separated trace file format is used due to
XDEBUG_TRACE_COMPUTERIZED.
The settings xdebug.collect_assignments, xdebug.collect_params, and xdebug.collect_return influence what information is logged to the trace file and the setting xdebug.trace_format influences the format of the trace file.
The full path and filename to which Xdebug traces is returned from this
function. This will be either the filename you pass in (potentially with
.xt added), or the auto generated filename if no filename has been
passed in.
Stops code coverage
This function stops collecting information, the information in memory will be destroyed. If you pass 0 as an argument, then the code coverage information will not be destroyed so that you can resume the gathering of information with the xdebug_start_code_coverage() function again.
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().
Stops monitoring functions
This function stops the function monitor. In order to get the list of monitored functions, you need to use the xdebug_get_monitored_functions() function.
Stops the current garbage collection statistics collection
Stop garbage collection statistics collection and closes the output file.
The function returns the filename of the file where the statistics were written to.
Stops the current function trace
Stop tracing function calls and closes the trace file.
The function returns the filename of the file where the trace was written to.
Returns the current time index
Returns the current time index since the starting of the script in seconds.
<?php
echo xdebug_time_index(), "\n";
for ($i = 0; $i < 250000; $i++)
{
// do nothing
}
echo xdebug_time_index(), "\n";
?>0.00038003921508789 0.76580691337585
Displays detailed information about a variable
This function displays structured information about one or more expressions that includes its type and value. Arrays are explored recursively with values. See the introduction of Development Helpers on which php.ini settings affect this function.
<?php
ini_set('xdebug.var_display_max_children', 3 );
$c = new stdClass;
$c->foo = 'bar';
$c->file = fopen( '/etc/passwd', 'r' );
var_dump(
array(
array(TRUE, 2, 3.14, 'foo'),
'object' => $c
)
);
?>array
0 =>
array
0 => boolean true
1 => int 2
2 => float 3.14
more elements...
'object' =>
object(stdClass)[1]
public 'foo' => string 'bar' (length=3)
public 'file' => resource(3, stream)