Home  >  Article  >  Backend Development  >  Xdebug Document (2) Variable Display Features, xdebug Document_PHP Tutorial

Xdebug Document (2) Variable Display Features, xdebug Document_PHP Tutorial

WBOY
WBOYOriginal
2016-07-12 08:50:191058browse

Xdebug document (2) Variable display feature, xdebug document

Xdebug can replace PHP's var_dump() function to display variable values. The version of xdebug includes different colors for array element/object attributes, maximum depth, and string length for different data types. There are also some functions here that handle variable display nicely.

Related settings:

xdebug.cli_color

Type: integer, default value: 0, starting from version 2.2 or above

When set to 1, xdebug will display the text output by var_dump trace in color when outputting in CLI mode and tty terminal. Under window, the ANSICON tool needs to be installed.

When set to 2, xdebug will always display var_dump and debug trace information in color regardless of whether it is connected to a tty terminal or whether ANSICON is installed. In this case, you may see an escape code at the end.

xdebug.overload_var_dump

Type: boolean, default value: 2 (before version 2.4, the default value is 1), starting from version 2.1 or above

xdebug by default overloads the var_dump() function to use its own improved version to display variables if html_errors is set to 1 or 2 in php.ini. If you really don't want this setting, you can set this setting to 0, but make sure it doesn't intelligently turn off html_errors.

It is recommended that you use a value of 2. In addition to its beautifully formatted display of var_dump() output, the output also displays filenames and line numbers. In addition, xdebug.file_link_format is also provided accordingly (new feature in version 2.3).

xdebug.var_display_max_children

Type: integer, default value: 128

This setting controls the display of the number of array elements and object properties when using xdebug_var_dump(), xdebug.show_local_vars or the trace function.

If it is not restricted, it can be set to -1 value.

This setting is not affected by Remot_Debuggin in any way.

xdebug.var_display_max_data

Type: integer, default value: 512

This setting controls the maximum string length displayed when using xdebug_var_dump(), xdebug.show_local_vars or the trace function.

If it is not restricted, it can be set to -1 value.

This setting is not affected by Remot_Debugging in any way.

xdebug.var_display_max_depth

Type: integer, default value: 3

This setting controls the display level of array elements and object properties when using xdebug_var_dump(), xdebug.show_local_vars or the trace function.

The maximum value is 1023, you can set it to -1 to indicate the maximum value.

This setting is not affected by Remot_Debugging in any way.

Related functions:

void var_dump( [mixed var [, ...]] )

Show the details of the variable.

This function has been covered by xdebug, see xdebug_var_dump() for details.

void xdebug_debug_zval( [string varname [, ...]] )

This function is used to display structured information of one or more variables, including their type, value and reference information. Arrays loop and recursively explore element values. This function is implemented differently from PHP's debug_zval_dump() function. It can solve the problem that the variable itself needs to be passed to the function. The Xdebug version of the function makes better use of the variable name to look up that variable in the internal symbol table and access all properties directly without having to deal with passing variables to the function. The information returned by this function can more accurately express zval information.

Example:

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

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

<span>/*</span><span>*
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
</span><span>*/</span>

void xdebug_debug_zval_stdout( [string varname [, ...]] )

Same as xdebug_debug_zval(), but this function does not display the information through the web API interface, but will be displayed directly on the stdout device (for example, it can be run in the single-process mode of apache and displayed in the terminal).

void xdebug_dump_superglobals()

This function displays the element value of the super global variable. The value to be displayed is set in xdebug.dump.* of php.ini. For example, the settings in php.ini are as follows:

Example:

xdebug.dump.GET=*<span>
xdebug</span>.dump.SERVER=<span>REMOTE_ADDR

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

Returns</span>:<span>

Dump </span><span>$_SERVER</span>

<span>$_SERVER</span>['REMOTE_ADDR'] =

<span>string</span> '127.0.0.1' (length=9<span>)

Dump </span><span>$_GET</span>

<span>$_GET</span>['var'] =

<span>string</span> 'fourty two' (length=10<span>)

</span><span>$_GET</span>['array'] =

<span>array</span>

  'a' => <span>string</span> 'a' (length=1<span>)

  </span>9 => <span>string</span> 'b' (length=1<span>)

 </span>

void xdebug_var_dump( [mixed var [, ...]] )

This function displays structured details of one or more expressions, including type and value. Arrays explore their element values ​​recursively.

Example:

<?<span>php
</span><span>ini_set</span>('xdebug.var_display_max_children', 3<span> );
</span><span>$c</span> = <span>new</span><span> stdClass;
</span><span>$c</span>->foo = 'bar'<span>;
</span><span>$c</span>-><span>file</span> = <span>fopen</span>( '/etc/passwd', 'r'<span> );
</span><span>var_dump</span><span>(
    </span><span>array</span><span>(
        </span><span>array</span>(<span>TRUE</span>, 2, 3.14, 'foo'),
        'object' => <span>$c</span><span>
    )
);
</span>?>  

<span>/*</span><span>*
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)
</span><span>*/</span>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133532.htmlTechArticleXdebug Document (2) Variable display feature, xdebug document Xdebug can replace PHP's var_dump() function to display variable values . The version of xdebug includes array element/object attributes for different data types...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn