appobs Posted September 25, 2015 Share Posted September 25, 2015 I have this at top of my index page: <?php $debug = 'off'; define (SCR_PATH, '/home/buildmyb/scripty'); // Obligatory config file include SCR_PATH . '/config.php'; // tools include SCR_PATH . '/tools.php'; ?> and this debug thing in each file that gets included: <?php $debug = ''; // initialise it so if anything other then empty, do NOT do the if if ($debug === '') { echo 'this line is in ' . __FILE__; echo '<hr>'; } ?> I'd like a single source for the debug thing but, obviously I can't include() it in each include or __FILE__ will show info for that, not the one I want. What do I do? Quote Link to comment Share on other sites More sharing options...
Solution Jacques1 Posted September 25, 2015 Solution Share Posted September 25, 2015 (edited) You can use debug_backtrace() to get the original file which included your debug script. It's the last entry in the list. Edited September 25, 2015 by Jacques1 Quote Link to comment Share on other sites More sharing options...
appobs Posted September 25, 2015 Author Share Posted September 25, 2015 Thanks, looking now Quote Link to comment Share on other sites More sharing options...
appobs Posted September 25, 2015 Author Share Posted September 25, 2015 You can use debug_backtrace() to get the original file which included your debug script. It's the last entry in the list. Nice one Test files set up as below, will throw something similar in my live app in a sec. index.php <h4>This line HTML in index.php</h4> <?php include 'config.php'; include 'tools.php'; ?> config.php and tools.php <h4>This line HTML in config.php</h4> <?php include 'debug.php'; ?> <h4>This line HTML in tools.php</h4> <?php include 'debug.php'; ?> debug.php <h4>This line HTML in debug.php</h4> <?php $array = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); echo basename($array['0']['file']) . ' is loaded<br>'; ?> Quote Link to comment 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.