Jump to content

Single source for my debug script so __FILE__ still works


appobs
Go to solution Solved by Jacques1,

Recommended Posts

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?

Link to comment
Share on other sites

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>';
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.