Getting Started With PHP Development: Tips for the PHP Developer

If you're just taking your first steps into PHP Development, here are some things that I would like to share:

1. Use PHP Core Functions and Classes

For common tasks, there are chances that there is already an existing PHP function or class that can be used for your present task. Check the PHP manual before starting coding manually. You can just use the trim() function if you want to remove the white space instead of creating a function from scratch!

2. Create a Configuration File

Instead of scattering your database connection settings scattered everywhere, create one master file that contains the overall settings and utilized them in PHP scripts. Using a config file is also a pattern that many use and which makes your code more modular and easy to maintain.

3. Always Clean up Data That Will Go into Database

Sanitizing your database inputs is very important. One needs to have a good understanding of what SQL injections actually are, and learn about SQL injection attacks and SQL injection cheat sheet.

There is a PHP function that can clean up the database for you: mysql_real_escape_string. mysql_real_escape_string

The function will take a regular string and sanitize it for you. If you use the function along with htmlspecialchars, it converts some reserved HTML characters and thus safeguard your database and your app against cross-site scripting attacks.

4. Leave Error Reporting Turned On in Development Stage

When building your application, it is essential for the PHP Developer to leave error_reporting and display_errors turned on which can facilitate him or her to see run-time errors and identify them.

The reason behind this is simple, you will know the errors cropping up sooner than expected and chances are, that you can fix them quickly. After building the application turn the feature off and then set their values as in it is ready for production.

5. Don't Over-Comment Your Code

Proper documentation of the code with the help of comments is good but do not over-comment them as good code is self-explanatory most of the times. Bad commenting makes your code look unstructured and will make your error fixing task tedious.

6. Keep your Essential Code Snippets Handy

You need some code snippets sometimes which might come in handy more than once in your career. Keeping them always available saves a lot of time. Most IDEs such as Eclipse and Dreamweaver have the ability to store code snippets. Using an app like DropBox will do the needful too!


Post a Comment

Note: Only a member of this blog may post a comment.