ironman32 Posted April 21, 2009 Share Posted April 21, 2009 What is a simple way to debug a script? Please bear in mind that I do not have access to my php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/155045-php-debugging/ Share on other sites More sharing options...
Maq Posted April 21, 2009 Share Posted April 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155045-php-debugging/#findComment-815465 Share on other sites More sharing options...
PFMaBiSmAd Posted April 21, 2009 Share Posted April 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155045-php-debugging/#findComment-815469 Share on other sites More sharing options...
Yesideez Posted April 21, 2009 Share Posted April 21, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/155045-php-debugging/#findComment-815477 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.