xdebug全部相關方法函數詳解(中文翻譯版)

這次翻譯部分藉助google翻譯,若有錯誤留言反饋 翻譯時間:2016年4月18日09:41:34php

 

xdebug.remote_enable = on
xdebug.profiler_enable = on
xdebug.profiler_enable_trigger = on
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "c:/wamp/tmp"html

開啓xdebug的相關的參數,安裝編譯這個不在這裏介紹web

 

Related Functions


void var_dump( [mixed var [, ...]] )
Displays detailed information about a variable
打印顯示一個變量的詳細信息

This function is overloaded by Xdebug, see the description for xdebug_var_dump().express

這個方法被xdebug重載了,詳細能夠查看 xdebug_var_dump函數數組

打印出來的東西會和var_debug有些不一樣,會更詳細服務器


bool xdebug_break()
Emits a breakpoint to the debug client.
發送給客戶端一個斷點調試

This function makes the debugger break on the specific line as if a normal file/line breakpoint was set on this line.cookie

此方法能夠像在普通文件設置斷點同樣,在指定行設置一個斷點app


string xdebug_call_class()
Returns the calling class
返回調用的類名

This function returns the name of the class from which the current function/method was called from.ide

此方法會從當前調用的方法返回類名函數

Example:

<?php
    function fix_string($a)
    {
        echo "Called @ ".
            xdebug_call_file().
            ":".
            xdebug_call_line().
            " from ".
            xdebug_call_function();
    }

    $ret = fix_string(array('Derick'));
?>

Returns:

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

string xdebug_call_file()
Returns the calling file

This function returns the filename that contains the function/method that called the current function/method.

此方法返回從當前調用的方法的包含的文件名

For an example see xdebug_call_class().


string xdebug_call_function()
Returns the calling function/method

This function returns the name of the function/method from which the current function/method was called from.

此方法會從當前調用的方法返回的方法名稱

For an example see xdebug_call_class().


int xdebug_call_line()
Returns the calling line

This function returns the line number that contains the function/method that called the current function/method.

此方法會從當前調用的方法返回的行數

For an example see xdebug_call_class().


boolean xdebug_code_coverage_started()
Returns whether code coverage is active.

Returns whether code coverage has been started.

返回代碼覆蓋是否是開始

Example:

<?php
    var_dump(xdebug_code_coverage_started());

    xdebug_start_code_coverage();

    var_dump(xdebug_code_coverage_started());
?>  

Returns:

bool(false)
bool(true)


void xdebug_debug_zval( [string varname [, ...]] )
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.

此方法顯示一個,或者多個變量的包括類型,值,引用計數的相關信息,數組遞歸打印(探索,沒找到對應的中文詞,語境翻譯)的值,這個方法實現方式和debug_zval_dump()不一樣,是爲了解決變量變自己傳遞給函數的顯示變量改變信息, Xdebug的版本是更好,由於它使用的變量名稱查找變量在內部符號表並訪問直接全部屬性,而沒必要處理與實際傳遞變量的函數。其結果是,這個函數返回的信息比PHP本身的函數來顯示zval的信息更加準確。

Support for anything but simple variable names (such as "a[2]" below) is supported since Xdebug 2.3.

Example:

<?php
    $a = array(1, 2, 3);
    $b =& $a;
    $c =& $a[2];

    xdebug_debug_zval('a');
    xdebug_debug_zval("a[2]");
?>

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

void xdebug_debug_zval_stdout( [string varname [, ...]] )
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).

此功能顯示關於一個或多個變量的結構化信息包括其類型,值和ref計數的信息的。數組與遞歸值探討。與Xdebug的調試的zval的差別()是該信息不經過Web服務器API層顯示,但在標準輸出直接顯示(因此,當你在單進程模式與Apache運行在控制檯上結束了)

這個方法

Example:

<?php
    $a = array(1, 2, 3);
    $b =& $a;
    $c =& $a[2];

    xdebug_debug_zval_stdout('a');

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)

void xdebug_disable()
Disables stack traces

Disable showing stack traces on error conditions.

禁用顯示錯誤條件下的堆棧跟蹤。


void xdebug_dump_superglobals()
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:

此方法做爲與指定此功能轉儲超級全局的元素的值。xdebug.dump的php.ini設置。對於低於在php.ini設置的例子是:

 

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)

void xdebug_enable()
Enables stack traces

Enable showing stack traces on error conditions.

開啓顯示錯誤條件下的堆棧跟蹤


array xdebug_get_code_coverage()
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:

<?php
    xdebug_start_code_coverage();

    function a($a) {
        echo $a * 2.5;
    }

    function b($count) {
        for ($i = 0; $i < $count; $i++) {
            a($i + 0.17);
        }
    }

    b(6);
    b(10);

    var_dump(xdebug_get_code_coverage());
?>  

Returns:

array
  '/home/httpd/html/test/xdebug/docs/xdebug_get_code_coverage.php' => 
    array
      5 => 
int
 1
      6 => 
int
 1
      7 => 
int
 1
      9 => 
int
 1
      10 => 
int
 1
      11 => 
int
 1
      12 => 
int
 1
      13 => 
int
 1
      15 => 
int
 1
      16 => 
int
 1
      18 => 
int
 1

void xdebug_get_collected_errors( [int clean] )
Returns all collected error messages
Introduced in version 2.1

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

當開啓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.

默認狀況下此功能將不能清除錯誤收集緩衝區。若是做爲參數傳遞true給這個函數則緩衝區也將被清除

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

該函數返回一個包含格式化爲「的Xdebug表」收集的全部錯誤的字符串。


array xdebug_get_declared_vars()
Returns declared variables

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));
?>

Returns:

array
  0 => 
string
 'a' (length=1)
  1 => 
string
 'b' (length=1)
  2 => 
string
 'item' (length=4)

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.


array xdebug_get_function_stack()
Returns information about the stack

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'));
?>

Returns:

array
  0 => 
    array
      'function' => 
string
 '{main}' (length=6)
      'file' => 
string
 '/var/www/xdebug_get_function_stack.php' (length=63)
      'line' => 
int
 0
      'params' => 
        array
          empty
  1 => 
    array
      'function' => 
string
 'fix_strings' (length=11)
      'class' => 
string
 'strings' (length=7)
      'file' => 
string
 '/var/www/xdebug_get_function_stack.php' (length=63)
      'line' => 
int
 18
      'params' => 
        array
          'b' => 
string
 'array (0 => 'Derick')' (length=21)
  2 => 
    array
      'function' => 
string
 'fix_string' (length=10)
      'class' => 
string
 'strings' (length=7)
      'file' => 
string
 '/var/www/xdebug_get_function_stack.php' (length=63)
      'line' => 
int
 12
      'params' => 
        array
          'a' => 
string
 ''Derick'' (length=8)


array xdebug_get_headers()
Returns all the headers as set by calls to PHP's header() function
Introduced in version 2.1

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.

返回全部已設置使用PHP header()函數,或任何其餘頭在PHP內部設置(如經過setcookie()函數)的標題,做爲一個數組

Example:

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

Returns:

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

array xdebug_get_monitored_functions()
Returns information about monitored functions
Introduced in version 2.4

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();
?>  

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)
  }
}

string xdebug_get_profiler_filename()
Returns the profile information filename

Returns the name of the file which is used to save profile information to.

返回其用於保存分析信息的文件的名稱。


integer xdebug_get_stack_depth()
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.

返回堆棧深度級別。一個腳本的主體是級別爲0而且每一個包括和/或功能調用添加一個到堆棧深度級別


string xdebug_get_tracefile_name()
Returns the name of the function trace file

Returns the name of the file which is used to trace the output of this script too. This is useful when xdebug.auto_trace is enabled.

返回一個也是用於跟蹤該腳本的輸出的文件名稱。當啓用xdebug.auto_trace時,這是很是有用的


bool xdebug_is_enabled()
Returns whether stack traces are enabled

Return whether stack traces would be shown in case of an error or not.

是否返回堆棧跟蹤會發生錯誤與否的狀況下顯示。


int xdebug_memory_usage()
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.

返回腳本使用的當前內存容量。 PHP5.2.1以前,若是PHP使用--enable-memory限制編譯這僅適用。從PHP5.2.1和此功能後始終可用。


int xdebug_peak_memory_usage()
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.

返回的最大內存使用量直到如今腳本。 PHP5.2.1以前,若是PHP使用--enable-memory限制編譯這僅適用。從PHP5.2.1和此功能後始終可用。


none xdebug_print_function_stack( [ string message [, int options ] ] )
Displays the current function stack.

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. (Introduced in Xdebug 2.1).

消息」的說法可讓你用本身的頭更換信息。 (在2.1 Xdebug的引入)。

Example:

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

Returns:

 
   
( ! ) 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_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.  (Introduced in Xdebug 2.3).

 若是這個選項被設置,那麼打印的堆棧跟蹤不會有一個標題。若是您想從本身的錯誤處理打印堆棧跟蹤,不然打印的位置是Xdebug的print_function棧()從所謂的,這很是有用。 (在Xdebug的2.3引入)。


void xdebug_start_code_coverage( [int options] )
Starts code coverage

This function starts gathering the information for code coverage. The 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: this line was executed
  • -1: this line was not executed
  • -2: this line did not have executable code on it
Value  -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.

 

This function has two options, which act as a bitfield:

XDEBUG_CC_UNUSED
Enables scanning of code to figure out which line has executable code. Without this option you the returned array will only have lines in them that were actually executed.
XDEBUG_CC_DEAD_CODE
Enables branch analyzes to figure out whether code can be executed.
Enabling those options make code coverage drastically slower.

 

You can use the options as shown in the following example.

Example:

<?php
xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
?>

void xdebug_start_error_collection()
Starts recording all notices, warnings and errors and prevents their display
Introduced in version 2.1

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 callxdebug_stop_error_collection().

當執行此功能時,Xdebug的將致使PHP不顯示任何通知,警告或錯誤。相反,它們根據Xdebug的正常錯誤格式規則(即,用紅色驚歎號偏差表),而後存儲在緩衝器格式化。這將繼續下去,直到你調用debug_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 get_collected_errors(檢索),隨後顯示。若是你想阻止破壞你的佈局的Xdebug強大的錯誤報告功能,這是很是有用的。


void xdebug_start_function_monitor( array $list_of_functions_to_monitor )
Starts function monitoring
Introduced in version 2.4

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:

您還能夠添加類方法和靜態方法來定義要監視的函數的數組。例如,爲了遇上靜態調用DramModel::能夠看到,動態調用Whisky->酒後,你會開始監控,包括:

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.

所定義的功能是區分大小寫的,而且靜態方法動態調用時纔會被發現。


void xdebug_start_trace( string trace_file [, integer options] )
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.trace_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.

開始從該點到跟蹤文件中的參數的文件跟蹤函數調用。若是沒有文件名給出,而後跟蹤文件將被放置在目錄中配置由xdebug.trace OUTPUT_DIR設置。若是一個文件名做爲第一個參數,該名稱是相對於當前的工做目錄。這個當前工做目錄可能會有所不一樣和你但願的,因此請使用你指定一個文件名的絕對路徑。使用PHP函數 getcwd()找出當前工做目錄是什麼

The name of the trace file is "{trace_file}.xt". If xdebug.auto_trace is enabled, then the format of the filename is "{filename}.xt" where the "{filename}" part depends on the xdebug.trace_output_name setting. The options parameter is a bitfield; currently there are three options:

跟蹤文件的名稱爲「{跟蹤文件}.xt」。若是xdebug.auto_trace被啓用,那麼文件名格式爲「{文件名}.xt」,其中「{文件名}」部分取決於xdebug.trace output_name中設置。選項參數是一個位域;目前有三種選擇:

XDEBUG_TRACE_APPEND (1)
makes the trace file open in append mode rather than overwrite mode
使得跟蹤文件以追加方式打開,而不是覆蓋模式
XDEBUG_TRACE_COMPUTERIZED (2)
creates a trace file with the format as described under  1 " xdebug.trace_format".
建立具備下1「xdebug.trace格式」中所述格式的跟蹤文件。
XDEBUG_TRACE_HTML (4)
creates a trace file as an HTML table
建立一個追蹤文件的html 表哥
XDEBUG_TRACE_NAKED_FILENAME (8)
Normally, Xdebug always adds ".xt" to the end of the filename that you pass in as first argument to this function. With the XDEBUG_TRACE_NAKED_FILENAME flag set, ".xt" is not added. (New in Xdebug 2.3).
一般狀況下,Xdebug的老是添加「.Xt」您在傳遞的第一個參數此功能的文件名末尾。隨着theXDEBUG_TRACE_NAKED_FILENAME標誌設置,「.xt」不添加。 (新增Xdebug的2.3)。
Unlike Xdebug 1, Xdebug 2 will not store function calls in memory, but always only write to disk to relieve the pressure on used memory. The settings xdebug.collect_includesxdebug.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.

 


void xdebug_stop_code_coverage( [int cleanup=true] )
Stops code coverage

This function stops collecting information, the information in memory will be destroyed. If you pass "false" as 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.

 

該功能將中止收集的信息,在內存中的信息將被銷燬。若是傳遞「假」的說法,那麼代碼覆蓋率信息不會被破壞,這樣就能夠再次恢復與xdebug_start_code_coverage()函數的信息收集。


void xdebug_stop_error_collection()
Stops recording of all notices, warnings and errors as started by  xdebug_start_error_collection()
Introduced in version 2.1

中止全部注意,警告和錯誤的記錄做爲發起者的XDebug start_error_collection()
推出2.1版本

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_start_error_collection()被停止。存儲在採集緩衝器中的偏差不會被刪除,並仍可經過Xdebug的get_collected_errors可讀取()。

 


void xdebug_stop_function_monitor()
Stops monitoring functions
Introduced in version 2.4

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.

此功能中止功能監測。爲了獲得的監測功能的列表中,您須要使用xdebug_get_monitored_functions()函數。


void xdebug_stop_trace()
Stops the current function trace

Stop tracing function calls and closes the trace file.

中止跟蹤函數調用和關閉跟蹤文件。


float xdebug_time_index()
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

void xdebug_var_dump( [mixed var [, ...]] )
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 Variable Display Features on which php.ini settings affect this function.

此功能顯示關於包括其類型和值的一個或多個表達式結構化信息。數組與遞歸值探討。看到介紹上php.ini的影響這個功能可變顯示功能的。

Example:

<?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
    )
);
?>  

Returns:

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)
相關文章
相關標籤/搜索