Language Translator

Hacking Zone

Hacking Tools
Attacking

Configure Windows

Windows Configuration

Novels

Mix Novels

Human Personality

Body Language
Introduction to Debugging and Error Checking PDF Print E-mail
Written by Harry   
Wednesday, 23 January 2008
Article Index
Introduction to Debugging and Error Checking
Page 2
Page 3


var_dump() can be useful in determining whether a variable has been set and whether it contains the information you where expecting.

The print_r function will recursively print an array. For example:

PHP Code:
<?php

$myArray 
= array('firstname' => 'Alan',
    
'surname' => 'Wagstaff',
    
'email' => ' This e-mail address is being protected from spam bots, you need JavaScript enabled to view it ',
    
'phone' => '12345-678901');

print_r($myArray);
In the code above, we create a basic array with a few details in it then use print_r() to echo it. The result will be something like the following:

Code:
Array
(
[firstname] => Alan
[surname] => Wagstaff
[email] => This e-mail address is being protected from spam bots, you need JavaScript enabled to view it
[phone] => 12345-678901
)
As you can see, this shows us the array keys and their values in a nicely formatted fashion so we can check what they contain. This is particularly useful when retrieving an array of database results to quickly check you got the data you expected.


Error Reporting and Logging

When writing and debugging our application, we will always want to display all notices, warnings and errors. Error messages hidden in a log file are not much good to us when debugging

The first thing we need to check is that we are set to display errors. You can do this by opening your PHP.INI and checking that "display_errors" is set to "On".

Next, at the top of our script we want to add:

PHP Code:
error_reporting(E_ALL); 
This will ensure that PHP shows us all errors, warnings and notices.


Conclusion

As you have seen, proper error checking in your applications will save vast amounts of time when debugging later. I hope that you have seen the importance of error checking and that to effectively debug an application it is a case of either starting from the top and working down until you find the bug, or starting from the error and working back up until you find the bug. Thankfully we have functions such as mysql_error() and var_dump() to help us in this task.




Digg!Reddit!Del.icio.us!Google!Live!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Spurl!Wists!Simpy!Newsvine!Blinklist!Furl!Fark!Blogmarks!Yahoo!Smarking!Netvouz!Shadows!RawSugar!Ma.gnolia!PlugIM!Squidoo!BlogMemes!FeedMeLinks!BlinkBits!Tailrank!linkaGoGo!Free social bookmarking plugins and extensions for Joomla! websites! title=
Comments
Add NewSearch
Only registered users can write comments!

Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved.



Last Updated ( Wednesday, 23 January 2008 )
 
< Prev   Next >
Your Ad Here

Donate us!!

Enter Amount:

RSS socialnet

Add to MyYahoo!
Subscribe in NewsGator Online
Add to Newsburst
Add to Google
Add to My AOL
Add to Pluck
Subscribe in FeedLounge
Add to Windows Live
Add to NetVibes
Subscribe in Rojo
Subscribe in Bloglines
Add to MyMSN
Add to Plusmo for your cellphone
Add to PageFlakes
Add to Technorati
Add to BlinkBits