Tips to Remember for new PHP programmers

Tips to Remember for new PHP programmers

PHP is one of the fastest growing web scripting languages on the Internet today. A PHP stand for Hypertext Preprocessor was designed explicitly for the website programming. PHP was invented by Rasmus Lerdorf in 1995 to enable the creation of dynamic web pages quickly and easily, PHP has exploded in growth and has been adopted by major vendors such as Linux that have included the language with their web servers. The language is easy to learn and works with a variety of operating systems. PHP’s strong performance, coupled with its modest learning curve, has made it the language of choice for many businesses wanting a cost effective rapid application development solution for the web.

Here are some the important tips that every PHP Programmer should know :

General

  • Dabble in OOP/Classes. After you’ve dabbled enough, you’ll probably use them in every script.
  • Session_Start should be called before any white space.
  • Use a Configuration File. This is a file that is included in the beginning of your script and sets up Constants and PHP Settings before your script runs.
  • Use Comments in Your Code. You will not remember why you did things a certain way if you come back to your code in a month. That isn’t a guess either, it’s a guarantee.
  • Using <?php and ?> make sure your PHP code works everywhere. That is really important.

Scope

  • Understand Scope. It means that variables inside functions can’t be accessed in variables outside the function.
  • The Global Scope is basically anything that isn’t in a function, class, or namespace. If you put too many variables in the Global Scope, you end up needing long variable names to seperate everything. You’ll understand this more when you get into OOPS Concept.

Reusability

  • Use functions to do code that you would normally do several times.
  • For each and While are your friends. They really are.
  • Separating classes or related functions into individual files makes it much easier to transition between projects that use the same code.

Sanitization

  • Overview: Don’t Trust any External Data.
  • Make sure all POST, GET, COOKIE, and all other data that is automatically generated is what you expect. If you have a ‘action’ variable in the URL (http://example.com?action=get), make sure that it one of the actions you are expecting. If it isn’t, replace it with a default or error.
  • Sanitize POST, GET, COOKIE Data.
  • Use MySQLi->Prepare for Database Based Queries.

Databases

  • Learn MySQL, SQL, and other database snytax if you want to deal with databases.
  • Use the proper PHP library for each database type. (MySQLi, PG, etc)
  • Some people suggest using PDO, as it works with most databases without having to change your code.
  • Use md5() to hash passwords. You might not need it immediately, but better to use it early.

For Best PHP Online Training please visit http://www.revanthtechnologies.com