Become Wordpress Professional - Your Ultimate Wordpress Guide

Monday, 14 October 2013

4 Most Useful Debugging functions in PHP

most useful debugging functions in PHPThere are a great number of useful functions that can be utilized for debugging in PHP Language. In order for one to master it, one of the main things to focus is on how to debug the code.

There are many cases in a programmers career where he faces different errors in the code which leads him to his code not functioning properly. For this purpose we have a number of great built-in functions for PHP. PHP is an extensive server side programming language and one of the most popular world wide. There are a great number of websites as well as web applications available now a days which are developed using PHP. Facebook is one of the most popular examples, which is developed using PHP language. Below are some most useful debugging functions that I use quite often when facing errors in code or the code is not working as per intention.

1) var_dump

One of the best functions that can be considered for debugging a code is var_dump(). It accepts either an variable (a string or an integer or boolean) , an array or an object. This function prints the value of a variable or the values of an array or object parsed into it, which pretty lets us know what data is being contained within the variables, arrays or objects. You can get more details about this function on official PHP.net site here

2) die

Another great method that can be taken under consideration while debugging is the die() method. Generally I use it where I need to stop the script from being executed further. For example this function can be useful within a script to check what values are we receiving from a form before storing them to a database. You can get more information about die() method on official PHP.net site here

3) mysql_error 

This is another yet important function that is used to debug MySQL queries. One might have some mistakes in a mysql query which can easily be figured out by the use of this function. You can read more on mysql_error() function on official PHP.net site here

4)  print_array

This is one of the most useful functions that can be utilized for debugging purpose while working with arrays. It accepts an array as a parameter and displays the array elements on screen.

This was a short list of useful PHP functions that I think are very useful for PHP developers, please feel free to let me know about other useful functions that can be utilized for debugging purpose via comments below and I will be more than happy to add them to the list above.

0 comments:

Post a Comment

Please Avoid Spamming. Comments will be moderated before they are published.