Jump to content

Recommended Posts

There are certain debugging techniques you can use depending on what kind of error or symptom you're seeing.  There is no correct answer to your question but here are some common tips.

 

The best way to debug is usually just to echo out variables/queries to see what values they contain.

 

You can also put this at the top of your page:

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

For more on error_reporting, read more here: error_reporting.

 

Link to comment
https://forums.phpfreaks.com/topic/155045-php-debugging/#findComment-815465
Share on other sites

To start with, you should be learning php, developing php code, and debugging php code on a local development system where you would have the ability to change php.ini settings.

 

Testing and debugging any kind of code involves supplying both expected and unexpected input and determining that the results are what you expect. When the results are not what you expect you then track down at what point the results are correct and at what point they are not in order to find where in the code the problem is at.

 

The easiest method to do this in a php script is to echo values at various points to see what exactly they are.

Link to comment
https://forums.phpfreaks.com/topic/155045-php-debugging/#findComment-815469
Share on other sites

If you've got a load of conditionals and note sure what's going on, what one is turing out to be TRUE and what code is being activated I plant an ECHO immediately after every single branch in a script within the area I'm concerned with so I can see the flow of the script. Example:

echo '1';
if ($alive==true)
  echo '2';
  //do some code
} else {
  echo '3';
}

 

I'll either get "12" or "13" but I can get something like 12478 depending on how many conditionals I'm running.

 

Plus ECHO'ing out variable content here and there helps as well. When it comesto type like arrays I dump them to see everything they hold:

var_dump($myarray);

 

Hope that helps.

Link to comment
https://forums.phpfreaks.com/topic/155045-php-debugging/#findComment-815477
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.