php - Why does foreach increase refcount by 2 instead of 1? -


nikic stated in another thread:

right before [a foreach] iteration $array "soft copied" use in foreach. means no actual copy done, refcount of zval of $array increased 2.

however, test code showing different result:

$array = array(0, 1, 2); xdebug_debug_zval('array'); // refcount=1, is_ref=0                             // far foreach ($array $key => $value) {     xdebug_debug_zval('array'); // refcount=3, is_ref=0 }                               // why refcount 3 instead of 2? 

just looking @ code, can see @ 2 array variables.

why refcount 3?

why isn't refcount 2 after foreach run?

the xdebug_debug_zval() looking @ $array variable , not $key variable. if change code to:

foreach ($array $key => $value) {     echo $key . " : " . $values . "<br>";     //xdebug_debug_zval('array');  } 

the correct values of array returned. don't have xdebug function can't test value put in there.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -