Sponsored Content
Full Discussion: Simply Explained
The Lounge What is on Your Mind? Cartoons for Geeks Simply Explained Post 302732619 by Linux Bot on Sunday 18th of November 2012 06:25:01 PM
Old 11-18-2012
Simply Explained

2012-11-19T00:18:03+01:00
Image


Tweet
Image Image Image Image
Image

Source...
 
DEBUG_ZVAL_DUMP(3)							 1							DEBUG_ZVAL_DUMP(3)

debug_zval_dump - Dumps a string representation of an internal zend value to output

SYNOPSIS
void debug_zval_dump (mixed $variable, [mixed $...]) DESCRIPTION
Dumps a string representation of an internal zend value to output. PARAMETERS
o $variable - The variable being evaluated. RETURN VALUES
No value is returned. EXAMPLES
Example #1 debug_zval_dump(3) example <?php $var1 = 'Hello World'; $var2 = ''; $var2 =& $var1; debug_zval_dump(&$var1); ?> The above example will output: &string(11) "Hello World" refcount(3) Note Beware the refcount The refcount value returned by this function is non-obvious in certain circumstances. For example, a developer might expect the above example to indicate a refcount of 2. The third reference is created when actually calling debug_zval_dump(3). This behavior is further compounded when a variable is not passed to debug_zval_dump(3) by reference. To illustrate, consider a slightly modified version of the above example: Example #2 <?php $var1 = 'Hello World'; $var2 = ''; $var2 =& $var1; debug_zval_dump($var1); // not passed by reference, this time ?> The above example will output: string(11) "Hello World" refcount(1) Why refcount(1)? Because a copy of $var1 is being made, when the function is called. This function becomes even more confusing when a variable with a refcount of 1 is passed (by copy/value): Example #3 <?php $var1 = 'Hello World'; debug_zval_dump($var1); ?> The above example will output: string(11) "Hello World" refcount(2) A refcount of 2, here, is extremely non-obvious. Especially considering the above examples. So what's happening? When a variable has a single reference (as did $var1 before it was used as an argument to debug_zval_dump(3)), PHP's engine opti- mizes the manner in which it is passed to a function. Internally, PHP treats $var1 like a reference (in that the refcount is increased for the scope of this function), with the caveat that if the passed reference happens to be written to, a copy is made, but only at the moment of writing. This is known as "copy on write." So, if debug_zval_dump(3) happened to write to its sole parameter (and it doesn't), then a copy would be made. Until then, the parameter remains a reference, causing the refcount to be incremented to 2 for the scope of the function call. SEE ALSO
var_dump(3), debug_backtrace(3), References Explained, References Explained (by Derick Rethans). PHP Documentation Group DEBUG_ZVAL_DUMP(3)
All times are GMT -4. The time now is 02:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy