Xdebug Break On Exception



As with normal exceptions, these Error exceptions will bubble up until they reach the first matching catch block. If there are no matching blocks, then any default exception handler installed with setexceptionhandler will be called, and if there is no default exception handler, then the exception will be converted to a fatal error and will be handled like a traditional error. Break on Exception. If a fatal error occurs while your program is being debugged, PHP Tools breaks on it by default. A fatal error is an error which prevents the continuation of the script execution, e.g. A parse error or an unhandled exception. In this case the debugger can be used to inspect the current program state. If you continue or step, the exception will continue to be thrown until it is either handled or you.

Browse

Xdebug debugger client for Sublime Text 2 and 3

Details

Installs

  • Total140K
  • Win78K
  • Mac32K
  • Linux30K
Apr 25Apr 24Apr 23Apr 22Apr 21Apr 20Apr 19Apr 18Apr 17Apr 16Apr 15Apr 14Apr 13Apr 12Apr 11Apr 10Apr 9Apr 8Apr 7Apr 6Apr 5Apr 4Apr 3Apr 2Apr 1Mar 31Mar 30Mar 29Mar 28Mar 27Mar 26Mar 25Mar 24Mar 23Mar 22Mar 21Mar 20Mar 19Mar 18Mar 17Mar 16Mar 15Mar 14Mar 13Mar 12Mar 11
Windows9141711181320101714171615121610222115211514111515172118141215161820211014172423251413182215
Mac4256296125243330481453135435234835354563841032
Linux172234624414411129213334645732375787847910864363

Readme

Source
raw.​githubusercontent.​com

Xdebug debugger client integration for Sublime Text.

Based on the Xdebug protocol functionality in SublimeXdebug package by Kindari.

Overview

Features

  • Remote debugging by configuring path mapping
  • Navigate on breakpoint hit to relevant file on specific line, when found on local drive
  • Customizable debugging layout for displaying stack history and context variables with syntax
  • Overview of breakpoints in all files and disable/enable breakpoints with simple click
  • Evaluate code within the current execution context, by setting watch expressions
  • Inspect (nested) context variables
  • Works on both Sublime Text 2 and 3

Commands

Here is a complete list of commands you can find Command Palette under the Xdebug namespace or in the menu under Tools / Xdebug:

Start/Stop debugging session

  • Start Debugging - Ctrl+Shift+F9 or ⌘+Shift+F9
  • Start Debugging (Launch Browser)
  • Restart Session
  • Stop Debugging - Ctrl+Shift+F10 or ⌘+Shift+F10
  • Stop Debugging (Launch Browser)
  • Stop Debugging (Close Windows)

Launch Browser menu option will only show if you have an url configured within settings.

Breakpoints

  • Add/Remove Breakpoint - Ctrl+F8 or ⌘+F8
  • Set Conditional Breakpoint - Shift+F8
  • Clear Breakpoints
  • Clear All Breakpoints

Watch expressions

  • Set Watch Expression
  • Edit Watch Expression
  • Remove Watch Expression
  • Clear Watch Expressions

Session commands

  • Evaluate
  • Execute
  • Status

Continuation commands

  • Run - Ctrl+Shift+F5 or ⌘+Shift+F5
  • Run To Line
  • Step Over - Ctrl+Shift+F6 or ⌘+Shift+F6
  • Step Into - Ctrl+Shift+F7 or ⌘+Shift+F7
  • Step Out - Ctrl+Shift+F8 or ⌘+Shift+F8
  • Stop
  • Detach

Other

  • Restore Layout / Close Windows - Ctrl+Shift+F11 or ⌘+Shift+F11
  • Settings - Default
  • Settings - User

Installation

Package Control

Execute “Package Control: Install Package” in the Command Palette to retrieve a list of available packages.Search in the list and install package Xdebug Client.

Git

Clone the repository by executing the following command in your Packages directory:

Download

Get the latest source from GitHub and extract the source into your Packages directory.

Note: You can locate your Packages directory in the menu underPreferences / Browse Packages..

Xdebug

In order to be able to debug your PHP scripts, you will need have Xdebug extension installed on your server.See here for installation instructions

Below is a configuration template for php.ini/xdebug.ini, be warned if you are on a Live environment, remote_connect_back allows every debug request from any source to be accepted.

For details about all available settings for configuring Xdebug, see here.

Configuration

The following settings can be configured in Xdebug.sublime-settings or in *.sublime-project files:

path_mapping
For remote debugging to resolve the file locations it is required to configure the path mapping with the server path as key and local path as value.

url
Determine which URL to launch in the default web browser when starting/stopping a session.

ide_key
An IDE key is used to identify with debugger engine when Sublime Text will start or stop a debugging session.

This package does not filter sessions by IDE key, it will accept any IDE key, also ones that do not match this configured IDE key. It is merely used when launching the default web browser with the configured URL.

host
Host address of network interface which Sublime Text should listen to connect with debugger engine.

When specifying host address of network interface, be sure to specify an IPv4 address as Sublime Text will listen for connections through an IPv4 socket.

port
Which port number Sublime Text should listen to connect with debugger engine.

max_children
Maximum amount of array children and object's properties to return.

max_data
Maximum amount of variable data to initially retrieve.

max_depth
Maximum amount of nested levels to retrieve of array elements and object properties.

break_on_start
Break at first line on session start, when debugger engine has connected.

break_on_exception
Break on exceptions, suspend execution when the exception name matches an entry in this list value.

close_on_stop
Always close debug windows and restore layout on session stop.

super_globals
Show information about super globals in context view.

fullname_property
Display property by fullname in context view.

hide_password
Microsoft excel free download for windows 10. Do not show possible password values in context view.

pretty_output
Render evaluated result as parsed output instead of raw XML.

launch_browser
Always launch browser on session start/stop.

Php Xdebug Stop On Exception

This will only work if you have the 'url' setting configured.

browser_no_execute
When launching browser on session stop do not execute script.
By using parameter XDEBUG_SESSION_STOP_NO_EXEC instead of XDEBUG_SESSION_STOP.

Php Xdebug Break On Exception

disable_layout
Do not use the debugging window layout.

debug_layout
Window layout that is being used when debugging.

breakpoint_group
breakpoint_index
context_group
context_index
stack_group
stack_index
watch_group
watch_index
Group and index positions for debug views.

breakpoint_enabled
breakpoint_disabled
breakpoint_current
current_line
Custom gutter icons for indicating current line or enabled/disabled breakpoints.

Do not use same icon for above values, because Sublime Text is unable to use the same icon for different scopes, in case there are duplicate icons detected it will fall back to the corresponding icon in the package.

python_path
Path to Python installation on your system.
Which is being used to load missing modules.

debug
Show detailed log information about communication between debugger engine and Sublime Text.

Below are examples how to configure your Xdebug.sublime-settings and *.sublime-project files.

Xdebug.sublime-settings

*.sublime-project

Troubleshoot

Can I have both SublimeTextXdebug and SublimeXdebug installed?

No. Having installed both packages can cause conflicts, because they might both listen to the same port for a debugger engine response and have similar keymapping.

However (project) settings from SublimeXdebug are compatible with SublimeTextXdebug.

How can I start a debugging session?

SublimeTextXdebug can start or stop a debugging session by launching the default web browser with the configured URL and parameter XDEBUG_SESSION_START or XDEBUG_SESSION_STOP which uses the configured IDE key as value. By default the IDE key is sublime.xdebug.

When you do not configure the URL, the plugin will still listen for debugging connections from Xdebug, but you will need to trigger Xdebug for a remote session.

If you want to run a start a debugging session from command line, before you run your script, you will need to set the environment variable XDEBUG_CONFIG with the IDE key.

Windows

UNIX

Make sure before defining the environment variable you have switched to the proper user environment.
As example you would set the environment variable as guest and execute the script as root(sudo), then root will not have the environment variable XDEBUG_CONFIG that was defined by guest.

How do I set a breakpoint and/or watch expression?

With SublimeTextXdebug you can easily add/remove breakpoints, which are send on session start.
Or set/edit/remove watch expressions, that are evaluated in the current execution context.

Setting a conditional breakpoints or watch expressions is quite easy, it is like an if statement in PHP.

As example you only want to stop on breakpoint when value of $number is equal to 13, then your Breakpoint condition would be $number13.
Another example would be when you would like to know the value of $item['image'] on each break, then your Watch expression would be $item['image'].

Another way is to set the breakpoint in your PHP code with the following function xdebug_break().

How to configure or disable breaking on exceptions?

By default the execution of a debugging session is suspended on each of the following exception names:* “Fatal error” - E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR* “Catchable fatal error” - E_RECOVERABLE_ERROR (since PHP 5.2.0)* “Warning” - E_WARNING, E_CORE_WARNING, E_COMPILE_WARNING, E_USER_WARNING* “Parse error” - E_PARSE* “Notice” - E_NOTICE, E_USER_NOTICE* “Strict standards” - E_STRICT* “Deprecated” - E_DEPRECATED, E_USER_DEPRECATED (since PHP 5.3.0)* “Xdebug”* “Unknown error”

In order to specify which exception names to suspend the execution of a debugging session, configure the break_on_exception setting with a list of the specific exception names by choice from the list shown above.

It is also possible to specify custom exceptions instead of all exceptions (“Fatal error”). For example if you would configure “MissingArgumentException” instead of “Fatal error”, it would not break on “InvalidParameterException”.

To disable breaking on exceptions either configure an empty list break_on_exception: [] or set as break_on_exception: false.

How can I customize/disable the debugging layout?

Re-adjust the layout in Sublime Text to your liking and then in console (Ctrl+`) you type window.get_layout() and set that value as your debug_layout.

Further customizing can be done by assigning the Xdebug views to a group/index with the breakpoint_group, breakpoint_index, context_group, context_index, stack_group, stack_index, watch_group, watch_index settings.

Or you can disable the debugging layout by setting disable_layout: true, which will open all Xdebug views in current active group/window on session start and does not change your layout.

How to solve ImportError?

Older versions of Sublime Text do not come with Python bundled and rely on your Python system installation.
Some systems do not include specific modules which are required by this package, such as pyexpat.

Configure the python_path setting to the path of your Python installation on your system which is either newer or has all required modules. For example: 'python_path' : '/usr/lib/python2.7'.

What to do when you experience any issues?

First check following possible solutions that could resolve any issues:

  • Use absolute paths in your path_mapping setting, Xdebug does not return symbolic links.
  • Breakpoint is on an empty line, Xdebug does not stop on empty lines.
  • Set port and xdebug.remote_port to different port (9001), default port 9000 might already be used by an other application.
  • Add an exception for Sublime Text (plugin_host.exe) to your firewall, response from Xdebug could be blocked by firewall.
  • Lower the max_data/max_depth/max_children settings to increase response speed or prevent crashing, Xdebug could return to much data to process.
  • Change permissions for Sublime Text and it's packages on your filesystem, Sublime Text or package might not have valid rights.

Do you still experience any issues, then create an issue including the following data:

  • What operating system(s) and version of Sublime Text are you using?
  • How did you install SublimeTextXdebug, Package Control, git clone or download?
  • Are you trying to debug the script remotely or locally, through browser or command line?
  • Which version of Xdebug extension do you have?
  • Can you post your project/settings file and Xdebug configuration from the *.ini located on your server.
  • Does the console window (Ctrl+`) show any more information regarding the error?

License

SublimeTextXdebug is released under the MIT License.

When Xdebug is activated it will show a stack trace whenever PHP decides to show a notice, warning, error etc. The information that stack traces display, and the way how they are presented, can be configured to suit your needs.

The stack traces that Xdebug shows on error situations (if display_errorsis set to On in php.ini) are quite conservative in the amount ofinformation that they show. This is because large amounts of information canslow down both the execution of the scripts and the rendering of the stacktraces themselves in the browser. However, it is possible to make the stacktraces show more detailed information with different settings.

Variables in Stack Traces

By default Xdebug will now show variable information in the stack traces thatit produces. Variable information can take quite a bit of resources, both whilecollecting or displaying. However, in many cases it is useful that variableinformation is displayed, and that is why Xdebug has the settingxdebug.collect_params. The script below, in combination with what the outputwill look like with different values of this setting is shown in the examplebelow.

The script

<?php
function foo( $a ) {
for (
$i = 1; $i < $a['foo']; $i++) {
if (
$i 500000) xdebug_break();
}
}
set_time_limit(1);
$c = new stdClass;
$c->bar = 100;
$a = array(
42 => false, 'foo' => 912124,
$c, new stdClass, fopen( '/etc/passwd', 'r' )
);
foo( $a );
?>

The results

Different values for the xdebug.collect_params setting give different output,which you can see below:


( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 34
Call Stack
#TimeMemoryFunctionLocation
10.000158564{main}( )./stack.php:0
20.000462764foo( )./stack.php:47

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31
Call Stack
#TimeMemoryFunctionLocation
10.000158132{main}( )./stack.php:0
20.000462380foo( array(5) )./stack.php:47

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31
Call Stack
#TimeMemoryFunctionLocation
10.000158564{main}( )./stack.php:0
20.000462812foo( array(5) )./stack.php:47

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31
Call Stack
#TimeMemoryFunctionLocation
10.000158564{main}( )./stack.php:0
20.000462812foo( array (42 => FALSE, 'foo' => 912124, 43 => class stdClass { public $bar = 100 }, 44 => class stdClass { }, 45 => resource(2) of type (stream)) )./stack.php:47

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31
Call Stack
#TimeMemoryFunctionLocation
10.000158132{main}( )./stack.php:0
20.000462380foo( $a = array (42 => FALSE, 'foo' => 912124, 43 => class stdClass { public $bar = 100 }, 44 => class stdClass { }, 45 => resource(2) of type (stream)) )./stack.php:47

Additional Information

On top of showing the values of variables that were passed to each functionXdebug can also optionally show information about selected superglobals by usingthe xdebug.dump_globals and xdebug.dump.* settings. The settings xdebug.dump_onceand xdebug.dump_undefined slightly modify when and which information is shownfrom the available superglobals. With the xdebug.show_local_vars setting you caninstruct Xdebug to show all variables available in the top-most stack level fora user defined function as well. The examples below show this (the script isused from the example above).


( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 34
Call Stack
#TimeMemoryFunctionLocation
10.000158564{main}( )./stack.php:0
20.000462764foo( )./stack.php:47

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 33
Call Stack
#TimeMemoryFunctionLocation
10.000158132{main}( )./stack.php:0
20.000462436foo( )./stack.php:47
Dump $_SERVER

( ! ) Fatal error: Maximum execution time of 1 second exceeded in /home/httpd/html/test/xdebug/docs/stack.php on line 31
Call Stack
#TimeMemoryFunctionLocation
10.000158132{main}( )./stack.php:0
20.000562588foo( )./stack.php:47
Dump $_SERVER
Variables in local scope (#2)

Filtering

Xdebug 2.6 introduces filtering capabilities for stack traces. A filter eitherincludes, or excludes, paths or class name prefixes (namespaces). You can use afilter to prevent anything from a vendor directory to appear in a stack trace,or to only include classes from specific namespaces.

To set-up a filter that shows only functions and methods that either have noclass name, or are prefixed with 'Xdebug', you would callxdebug_set_filter() with:

Example:

With this filter set-up, you will only see functions (without class) and allmethod calls of classes that start with 'Xdebug'. This includes built-in PHPfunctions (such as strlen()) and calls toXdebugTest::bar(). The filter does not enforce that 'Xdebug' isthe name of a namespace, and only does a strict character comparison from thestart of the fully qualified class name. Add a to the prefix tomake sure only classes in the Xdebug namespace are included.

The full documentation for the arguments to xdebug_set_filter() aredescribed on its own documentation page.

Related Settings and Functions

  • integerxdebug.cli_color = 0
  • booleanxdebug.collect_includes = true
  • integerxdebug.collect_params = 0
  • booleanxdebug.collect_vars = false
  • stringxdebug.dump.* = Empty
  • booleanxdebug.dump_globals = true
  • booleanxdebug.dump_once = true
  • booleanxdebug.dump_undefined = false
  • stringxdebug.file_link_format =
  • stringxdebug.filename_format = ..%s%n
  • stringxdebug.manual_url = http://www.php.net
  • integerxdebug.show_error_trace = 0
  • integerxdebug.show_exception_trace = 0
  • integerxdebug.show_local_vars = 0
  • integerxdebug.show_mem_delta = 0
  • integerxdebug.var_display_max_children = 128
  • integerxdebug.var_display_max_data = 512
  • integerxdebug.var_display_max_depth = 3
  • xdebug_get_declared_vars() : array
  • xdebug_get_function_stack() : array
  • xdebug_get_monitored_functions() : array
  • xdebug_get_stack_depth() : int
  • xdebug_print_function_stack() : void
  • xdebug_start_function_monitor() : void
  • xdebug_stop_function_monitor() : void

Settings

integer xdebug.cli_color = 0#

Introduced in Xdebug >= 2.2

If this setting is 1, Xdebug will color var_dumps and stack traces output when in CLI mode and when the output is a tty. On Windows, the ANSICON tool needs to be installed.

If the setting is 2, then Xdebug will always color var_dumps and stack trace, no matter whether it's connected to a tty or whether ANSICON is installed. In this case, you might end up seeing escape codes.

See this article for some more information.

boolean xdebug.collect_includes = true#

This setting, defaulting to 1, controls whether Xdebug should write thefilename used in include(), include_once(), require() or require_once() to thetrace files.

integer xdebug.collect_params = 0#

This setting, defaulting to 0, controls whether Xdebug should collectthe parameters passed to functions when a function call is recorded in eitherthe function trace or the stack trace.

The setting defaults to 0 because for very largescripts it may use huge amounts of memory and therefore make it impossible forthe huge script to run. You can most safely turn this setting on, but you canexpect some problems in scripts with a lot of function calls and/or huge datastructures as parameters. Xdebug 2 will not have this problem with increasedmemory usage, as it will never store this information in memory. Instead itwill only be written to disk. This means that you need to have a look at thedisk usage though.

This setting can have four different values. For each of the values adifferent amount of information is shown. Below you will see what informationeach of the values provides. See also the introduction of the featureStack Traces for a few screenshots.

ValueArgument Information Shown
0None.
1Type and number of elements (f.e. string(6), array(8)).
2

Type and number of elements, with a tool tip for the full information 1.

3Full variable contents (with the limits respected as set by xdebug.var_display_max_children, xdebug.var_display_max_data and xdebug.var_display_max_depth.
4Full variable contents and variable name.
5PHP serialized variable contents, without the name.

1 in the CLI version of PHP it will not have the tool tip, nor in output files.

boolean xdebug.collect_vars = false#

This setting tells Xdebug to gather information about which variablesare used in a certain scope. This analysis can be quite slow as Xdebug hasto reverse engineer PHP's opcode arrays. This setting will not record whichvalues the different variables have, for that use xdebug.collect_params.This setting needs to be enabled only if you wish to usexdebug_get_declared_vars().

string xdebug.dump.* = Empty#

* can be any of COOKIE, FILES, GET, POST, REQUEST, SERVER, SESSION.These seven settings control which data from the superglobals is shown when anerror situation occurs.

Each of those php.ini setting can consist of a comma separated list ofvariables from this superglobal to dump, or * for all of them.Make sure you do not add spaces in this setting.

In order to dump the REMOTE_ADDR and the REQUEST_METHOD when an erroroccurs, and all GET parameters, add these settings:

boolean xdebug.dump_globals = true#

When this setting is set to true, Xdebug adds the valuesof the super globals as configured through the xdebug.dump.* to on-screen stacktraces and the error log (if enabled).

boolean xdebug.dump_once = true#

Controls whether the values of the superglobals should be dumped on allerror situations (set to 0) or only on the first (set to 1).

boolean xdebug.dump_undefined = false#

If you want to dump undefined values from the superglobals you should setthis setting to 1, otherwise leave it set to 0.

string xdebug.file_link_format = #

Introduced in Xdebug >= 2.1

This setting determines the format of the links that are made inthe display of stack traces where file names are used. This allows IDEs to setup a link-protocol that makes it possible to go directly to a line and file byclicking on the filenames that Xdebug shows in stack traces. An example format might look like:

The possible format specifiers are:

SpecifierMeaning
%fthe filename
%lthe line number

For various IDEs/OSses there are some instructions listed on how to make this work:

Firefox on Linux

  • Open about:config
  • Add a new boolean setting 'network.protocol-handler.expose.xdebug' and set it to 'false'
  • Add the following into a shell script ~/bin/ff-xdebug.sh:Add to that one of (depending whether you have komodo, gvim or netbeans):
    • komodo $f -l $l
    • gvim --remote-tab +$l $f
    • netbeans '$f:$l'
  • Make the script executable with chmod +x ~/bin/ff-xdebug.sh
  • Set the xdebug.file_link_format setting to xdebug://%f@%l

Windows and netbeans

  • Create the file netbeans.bat and save it in your path (C:Windows will work):

    Note: Remove the last line if you don't have nircmd.

  • Save the following code as netbeans_protocol.reg:

    Note: Make sure to change the path to Netbeans (twice), as well as the netbeans.bat batch file if you saved it somewhere else than C:Windows.

  • Double click on the netbeans_protocol.reg file to import itinto the registry.
  • Set the xdebug.file_link_format setting to xdebug.file_link_format ='netbeans://open/?f=%f:%l'

string xdebug.filename_format = ..%s%n#

Introduced in Xdebug >= 2.6

This setting determines the format with which Xdebug rendersfilenames in HTML stack traces (default: ..%s%n) and locationinformation through the overloaded xdebug_var_dump() (default:%f).

The possible format specifiers are listed in this table. The example output isrendered according to the full path/var/www/vendor/mail/transport/mta.php.

SpecifierMeaningExample Output
%aAncester: Two directory elements and filenamemail/transport/mta.php
%fFull path/var/www/vendor/mail/transport/mta.php
%nName: Only the file namemta.php
%pParent: One directory element and the filenametransport/mta.php
%sDirectory separator/ on Linux, OSX and other Unix-like systems, on Windows

string xdebug.manual_url = http://www.php.net#

Available in Xdebug < 2.2.1

This is the base url for the links from the function traces and errormessage to the manual pages of the function from the message. It is advisableto set this setting to use the closest mirror.

integer xdebug.show_error_trace = 0#

Introduced in Xdebug >= 2.4

When this setting is set to 1, Xdebug will show a stack trace wheneveran Error is raised - even if this Error is actually caught.

integer xdebug.show_exception_trace = 0#

When this setting is set to 1, Xdebug will show a stack trace wheneveran Exception or Error is raised - even if this Exception or Error is actually caught.

Error 'exceptions' were introduced in PHP 7.

integer xdebug.show_local_vars = 0#

When this setting is set to something != 0 Xdebug's generated stack dumpsin error situations will also show all variables in the top-most scope. Bewarethat this might generate a lot of information, and is therefore turned off bydefault.

integer xdebug.show_mem_delta = 0#

When this setting is set to something != 0 Xdebug's human-readablegenerated trace files will show the difference in memory usage between functioncalls. If Xdebug is configured to generate computer-readable trace files thenthey will always show this information.

integer xdebug.var_display_max_children = 128#

Controls the amount of array children and object's properties are shownwhen variables are displayed with either xdebug_var_dump(),xdebug.show_local_vars or through Function Trace.

To disable any limitation, use -1 as value.

This setting does not have any influence on the number of children that issend to the client through the Step Debugging feature.

integer xdebug.var_display_max_data = 512#

Controls the maximum string length that is shownwhen variables are displayed with either xdebug_var_dump(),xdebug.show_local_vars or through Function Trace.

To disable any limitation, use -1 as value.

This setting does not have any influence on the number of children that issend to the client through the Step Debugging feature.

integer xdebug.var_display_max_depth = 3#

Controls how many nested levels of array elements and object properties arewhen variables are displayed with either xdebug_var_dump(),xdebug.show_local_vars or through Function Trace.

The maximum value you can select is 1023. You can also use -1 asvalue to select this maximum number.

This setting does not have any influence on the number of children that issend to the client through the Step Debugging feature.

Functions

xdebug_get_declared_vars() : array#

Returns an array where each element is a variable name which is defined in the current scope. The setting xdebug.collect_vars needs to be enabled.

Example:

<?php
class strings {
static function
fix_strings($a, $b) {
foreach (
$b as $item) {
}
var_dump(xdebug_get_declared_vars());
}
}
strings::fix_strings(array(1,2,3), array(4,5,6));
?>

In PHP versions before 5.1, the variable name 'a' is not in the returned array, as it is not used in the scope where the function xdebug_get_declared_vars() is called in.

xdebug_get_function_stack() : array#

Returns an array which resembles the stack trace up to this point. The example script:

Example:

<?php
class strings {
function
fix_string($a)
{
var_dump(xdebug_get_function_stack());
}
function
fix_strings($b) {
foreach (
$b as $item) {
$this->fix_string($item);
}
}
}
$s = new strings();
$ret = $s->fix_strings(array('Derick'));
?>

xdebug_get_monitored_functions() : array#

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:

<?php
/* Start the function monitor for strrev and array_push: */
xdebug_start_function_monitor( [ 'strrev', 'array_push' ] );
/* Run some code: */
echo strrev('yes!'), 'n';
echo
strrev('yes!'), 'n';
var_dump(xdebug_get_monitored_functions());
xdebug_stop_function_monitor();
?>

xdebug_get_stack_depth() : int#

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_print_function_stack( string $message = 'user triggered', int $options = 0 ) : void#

Displays the current function stack, in a similar way as what Xdebug would display in an error situation.

Xdebug

The 'message' argument allows you to replace the message in the header with your own.

Example:

<?php
function foo( $far, $out )
{
xdebug_print_function_stack( 'Your own message' );
}
foo( 42, 3141592654 );
?>

The bitmask 'options' allows you to configure a few extra options. The following options are currently supported:

XDEBUG_STACK_NO_DESC
If this option is set, then the printed stack trace will not have a header. This is useful if you want to print a stack trace from your own error handler, as otherwise the printed location is where xdebug_print_function_stack() was called from.

xdebug_start_function_monitor( array $listOfFunctionsToMonitor ) : void#

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.

Example:

<?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:

Example:

<?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.

xdebug_stop_function_monitor() : void#

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.