php - What state of function arguments does debug_backtrace() capture? -


some abstract code:

function test($a = 5) {   debug_backtrace();   = 10; } 

what debug_trace tell arguments of test function?
capture $a 5 or 10?

if call function example way:

test(4); 

it'll capture '4'.

and if call way:

test(); 

it'll capture no data arguments. suppose parser doesn't initialize arguments if haven't been used anywhere. (calling debug_backtrace doesn't count.)

i've done more researches , things have turned out little bit unexpected (personally me) if passing arguments reference... logical enough, admit.

if use following code:

<?php     function test2(&$a) {             $a = 5;             test($a);             $a = 8;     }     function test(&$a) {             $a = 6;             print_r(debug_backtrace());             $a = 7;     }     $test = 1;     test2($test); 

we'll such output:

array (   [0] => array (     [file] => /var/www/localhost/htdocs/index.php     [line] => 4     [function] => test     [args] => array ( [0] => 6 )    )   [1] => array (     [file] => /var/www/localhost/htdocs/index.php     [line] => 13     [function] => test2     [args] => array ( [0] => 6 )    )  ) 

so debug_backtrace() prints current state of function arguments passed references (when debug_backtrace() called), no matter if had value on parent function call.
careful when debugging! :)


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -