surion Posted October 20, 2008 Share Posted October 20, 2008 hi, i have a function who logs my queries when they are performed: function mysql_log_query($file,$line,$sql) { //do something with $file & $line return mysql_query($sql); } called this way: $results = mysql_log_query(__FILE__,__LINE__,"some sql query"); i used to give __FILE__ & __LINE__ as arguments to to make the logging. but now i learned i can use debug_backtrace so this becomes function mysql_log_query($sql) { $backtrace = array(); $backtrace = debug_backtrace(); return mysql_query($sql); } now, i have the next problem: sometimes i can get the line & file with $backtrace['file'] or $backtrace['line], YET, sometimes $backtrace becomes an ARRAY of arrays For example: what i want: $backtrace = array('file => 'file', 'line' => 'line',... other backtrace info ...); what i don't want but what i do get sometimes: $backtrace = array(array(file => file, line => line, ... other backtrace info ...), array(file => file, line => line,... other backtrace info ...)) why does it sometimes become an array of arrays? how can i make sure that that does NOT happen, OR, is there a way to read those arrays of arrays correct? i mean, a function is at its current instance only called from 1 file, and or 1 line,... if you know what i mean,... Quote Link to comment https://forums.phpfreaks.com/topic/129238-solved-debug_backtrace/ Share on other sites More sharing options...
surion Posted October 20, 2008 Author Share Posted October 20, 2008 does it probably remember former backtrace information thus creating an array of arrays? if yes, that means the info is saved somewhere out of the function? if yes, is there a way to flush that info after each $backtrace = debug_backtrace() ? Quote Link to comment https://forums.phpfreaks.com/topic/129238-solved-debug_backtrace/#findComment-670112 Share on other sites More sharing options...
surion Posted October 20, 2008 Author Share Posted October 20, 2008 up Quote Link to comment https://forums.phpfreaks.com/topic/129238-solved-debug_backtrace/#findComment-670260 Share on other sites More sharing options...
rhodesa Posted October 20, 2008 Share Posted October 20, 2008 it should always return an array of backtrace items, the number of items will depend on how deep you are. if you are inside a function called by another function, you will get two items. from the looks of it, you will always want the first item, so just use: function mysql_log_query($sql) { list($backtrace) = debug_backtrace(); return mysql_query($sql); } Quote Link to comment https://forums.phpfreaks.com/topic/129238-solved-debug_backtrace/#findComment-670274 Share on other sites More sharing options...
surion Posted October 20, 2008 Author Share Posted October 20, 2008 very intresting information, didn't know that a call by a call by a call for example was the cause of 3 array items thanks alot for your reply, topic solved Quote Link to comment https://forums.phpfreaks.com/topic/129238-solved-debug_backtrace/#findComment-670324 Share on other sites More sharing options...
rhodesa Posted October 21, 2008 Share Posted October 21, 2008 hence 'backtrace'...it shows all the steps the program took to that point Quote Link to comment https://forums.phpfreaks.com/topic/129238-solved-debug_backtrace/#findComment-670573 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.