Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6027765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:38:26+00:00 2026-05-23T04:38:26+00:00

I’m wondering how one creates a debug room for their applications. My example is

  • 0

I’m wondering how one creates a debug room for their applications.

My example is that I output variable content to the screen for me to have a visual on what my variables are doing throughout the process. To make sure they are doing what they should be doing. (poor man’s tdd?)

——–NEW CODE——————–

So this is what I came up with for now but it involves a !!global variable!!

I have a common file that is included with all the pages of my script. In there I put the following:

<?php //COMMON FILE
$debug_mode = 'on'; //my trigger

if( strtolower($debug_mode) == 'on'){
    $debug = "<hr /><pre>";
    if( file_exists('debug_mode.php') ){  //This file will never be used in a
        include('debug_mode.php');    //a production environment
    }
}

function debug($str, &$debug){
    if( function_exists('debugff') ){
        $str = debugff($str, $debug);
    }
    else{
        unset($debug);
    }
}
?>

.

<?php //DEBUG_MODE FILE NEVER USED IN PRODUCTION MODE
if( strtolower($debug_mode) == 'on'){ 
    function debugff($debugstring, &$debug){ 

        global $debug;

        if( is_null($debugstring) ){
            echo $debug . "</pre><hr />";
        }
        else{ 
            $debug .= $debugstring . "\n";
        }
    }
}

?> 

To use the script I use a call to the debug function.

debug(“username:$user”, $debug);

And I can do that a million times. and when I want to print the results I simply call

debug(null, $debug);

I’ve heard countless number of times to never use a global variable and this is the first time I implement it. Granted the way I have it set up would mean that in the ‘real world’ the global variable will never get called, but how would I get the global variable out of here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:38:27+00:00Added an answer on May 23, 2026 at 4:38 am

    Try to learn a PHP framework. They solve these problems better and in an OOP way.

    Anyway, in your example, you can remove a lot of the code:

    $debug_mode = TRUE;
    
    function dump() {
      global $debug_mode;
    
      if ($debug_mode) {
        call_user_func_array('var_dump', func_get_args());
      }
    }
    

    You can then dump your variables with dump($var1, $var2, $var3) and don’t worry about the production mode outside this function. The dumps will not be showed once you trigger the debug mode off.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have text I am displaying in SIlverlight that is coming from a CMS
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have some data like this: 1 2 3 4 5 9 2 6
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.