There are plenty of great PHP introduction articles on the web. Many of these introductions have code samples to help you get started. If you are completely new to PHP I highly recommend the following introductions:
The purpose of this article is to help you determine if PHP is the right technology for your web application.
What is PHP?
PHP was invented to facilitate the rapid creation of dynamic websites. Like its parent language, Perl, PHP is an interpreted language meaning you don’t have to compile your program every time you want to run it. You simply access the PHP file from your PHP-enabled web server. Also like Perl, PHP is extremely easy to start using. A hello world program in PHP looks like this:
<html> <body> <?php echo "Hello World"; ?> </body> </html>
Easy right? Well not so fast. Easy also lends itself to sloppy code since PHP gives you a hundred different ways to achieve the same. This is not a bad thing. It just means that if you are building anything bigger than a personal home page you will save yourself a lot of headaches if you carefully consider some design decisions now.
Procedural vs Object Oriented Programming (OOP)
PHP gives you the option of programming in both procedural and object oriented styles. With the release of PHP5, PHP added many object oriented features that were sorely missed in PHP4. With a fully usable OOP stack PHP is now capable of building an application using only OOP.
The decision to use procedural vs OOP comes down to the background of your development team. If your developers are experts in managing functions and can maintain clear, concise documentation then procedural should work fine.
Otherwise you should consider using OOP. OOP forces your developers to organize their code by building objects and grouping variables and methods around those objects. Even with poor documentation an OOP code base is still manageable due to the inherit documentation of object references. OOP will also allow your development team to take advantage of many of the newest add-ons to PHP like frameworks.
A PHP framework is a set of tools designed to standardize the common aspects of application development. Many applications have common requirements including model-view-controller, database access, and user security. These are only a few of the features you gain by adopting a framework.
Two of the popular PHP frameworks are Zend and CakePHP. Zend is commercial company and a major supporter of PHP. Much of the code behind PHP4 and PHP5 comes from Zend. They are the biggest player in the PHP market and their framework should be actively supported for a long, long time. CakePHP started when there were very few PHP frameworks to choose from. They are predominantly community supported and very recently started a spin-off commercial venture providing consulting services for CakePHP. I like to see open-source projects supported by viable commercial ventures because this ensures its project members will be able to feed themselves and family members.
For more in-depth comparisons of the two frameworks I highly recommend the following articles:
Reusable Code (aka Libraries)
The longer a programming language is in use the more reusable code you will find for that language. PHP is no exception. The PHP community has created PEAR (PHP Extension and Application Repository) as its central repository for reusable code. There are 150+ packages available for PHP5 and hundreds of others available for other PHP frameworks. Before developing a new module for your application it is always a good idea to check PEAR to see if someone has already developed the same functionality.
This concludes my introduction to PHP. I hope it has given you some insight into the world of PHP programming. This is the first in a series of introductions into programming languages that I use and enjoy. If you would like to share your thoughts on this article I would love to hear them in the comments section below.