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 7869151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:13:42+00:00 2026-06-03T01:13:42+00:00

I am quite new to programming, when I develop my program I use a

  • 0

I am quite new to programming, when I develop my program I use a simple strategy to debug it: I write the program to print along the debugging messages as it operate the significant statements, for example

function foo1($number)
{
  //foo_print("I am function foo1({$number}). <br/>");
  //foo_print("I am going to increase 'count' by {$number}. <br/>");

  $GLOBALS["count"] = $GLOBALS["count'] + $number;

  //foo_print("Now 'count' = {$GLOBALS["count"]}, I finished my task, BYE BYE. <br/>");

}

function isFoo($number)
{
  //foo_print("I am function isFoo({$number}). <br/>");
  //foo_print("I am checking if the number < 3 or not, if so, it is Foo, if not, it is not Foo. <br/>");
  if($number <= 3)
  {
    //foo_print("Found that number = {$number} <= 3, I return true, BYE BYE. <br/>");
    return true;
  }

  //foo_print("Found that number = {$number} > 3, I return false, BYE BYE. <br/>");
  return false;
}

I call them debugging messages but, as you see, they’re actually the thoroughly comments describing what does the program do on each line. I just write the function foo_print() to print them out when I am debugging the program. And comment them out in real use.

Instead of inserting and removing the comment sign ‘//’ line by line in and out when switch between real run mode and debugging mode, I have the function foo_print to do the work: It can be set to turn on or off.

define(FOO_PRINT, 1)
function foo_print($message)
{
  if(FOO_PRINT) print $message;
  // if FOO_PRINT == 0 then do nothing.
}

But I think this method is ineffective, it has to check FOO_PRINT every time before printing a message.

My question is either or both of the following

  • Can I do something to tell php to ignore my foo_print() function when I don’t want to use it?

  • Perhaps, instead of using foo_print function, I should write the messages in plain comment style using ‘//’ sign and then tell php interpreter to print those comment messages when in debugging mode. Can I do that?

I think, other than debugging ease, this method will be of advantage that it can help me understand the program when I come back to see it in later days. (It very long and complicated for me that I believe I will forget it soon.)

I found it very complicated for me now to use advanced IDEs and debugging tools to develop my program. I believe some of these advanced debugging tools can do something similar to what I want, but I’ve tried on PHP-eclipse and xdebug for a week and it got me nowhere. thank you very much.

  • 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-06-03T01:13:44+00:00Added an answer on June 3, 2026 at 1:13 am

    You could define two functions, one of which outputs the debug data and the other one doesn’t. Then use a variable name to contain the name of the function you want to call and do your debugging by calling the function in the variable. Like this:

    function debug_print($data) {
        echo $data;
    }
    function debug_none($data) {
    }
    
    $debug = 'debug_print';
    $debug('Testing one'); // This prints out 'Testing one'
    
    $debug = 'debug_none';
    $debug('Testing two'); // This doesn't print out anything
    

    If you do this, don’t forget to add global $debug to any functions that want to use the function.

    EDIT: There is also a more object oriented way to achieve the same result. You could define an interface and write a couple of implementations for it, allowing you to choose which one to use at runtime.

    $debugmode = true;
    
    interface Debugger {
        public function out($data);
    }
    
    class EchoDebugger implements Debugger {
        public function out($data) {
            echo $data;
        }
    }
    
    class NullDebugger implements Debugger {
        public function out($data) {
            // Do nothing
        }
    }
    
    if($debugmode)
        $debugger = new EchoDebugger();
    else
        $debugger = new NullDebugger();
    
    $debugger->out('This will be output if $debugmode is true');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm quite new to GUI programming in C++ and I'm trying to use the
I'm quite new into the programming game, I've been working on this program for
I'm quite new to java programming, but I'll try to use the correct terms
I am quite new to programming, i have a question please help me. (
I am quite new to SQLAlchemy, or even database programming, maybe my question is
I'm quite new to php and have been reading Larry Ullman book to develop
I'm quite new to jQuery, and I've written a simple function to check the
I'm quite new in programming .I wrote the below code in order to prompt
I'm quite new to programming larger applications. I have now written a command line
I'm quite new to Java Programming and am writing my first desktop app, this

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.