PHP
By Simon Bisson
Simon Bisson explains how the growth of Web applications led to programming environments such as PHP.
HardCopy Issue: 39 | Found In: Development | Published: 01/02/2008 | Last Revision: 06/07/2010
The Internet boom showed us that Web applications needed more than just CGI and HTML. Perl applications formed the backbone of the developing Web, but it was the arrival of tag-based programming environments like ASP, ColdFusion and PHP that gave Web developers the rapid application development platforms they were demanding.
Server side scripting tools simplified development and could be supported by Web design tools like Adobe’s Dreamweaver. Server side scripting has evolved to meet the demands of the Web. ASP turned into ASP.NET, ColdFusion became a front end for Java, but it was the originally CGI-based PHP that became the tool for many Web developers. PHP went through several evolutions, moving away from being written as a set of C-based CGI programs to having its own object-oriented interpreter with plug-in support for most of the main Web server platforms. The history of PHP is complex as the development team changed between the release of PHP 2 and PHP 3.
You can speed up PHP application development using the various frameworks currently available. These give developers a selection of components along with tools to integrate them into applications.
The Zend Framework offers a set of tools that make it easier to build community-based applications. Key components include tools for working with database content, handling user sessions and authentication. You’ll also find components to help with internationalisation – a perennial problem for Web application developers. The Zend Framework can help with linking Web applications with n-tier enterprise solutions as it includes components that simplify use of PHP in a Model-View-Controller design pattern.
Other well known PHP frameworks include Akelos which offers PHP developers a port of Rails, along with its templating language to help with page design and layout. PHP developers can use the Drupa framework to build Web applications driven by a flexible content management system. You’ll find that most PHP frameworks require your Web application architectures to include databases and are often designed to work with MySQL.
Like many open source projects, PHP is produced by a distributed group of developers and released under its own PHP licence. That said, the development tools company Zend has a lot of influence as it employs many of the lead developers. The Zend team has developed the most commonly used PHP engine and is currently working on PHP 6 which is due in 2008. There are several implementations of PHP as well as the reference version. These include a .NET compiler that runs on Mono and pure Java versions that let you work with Java code from your PHP applications.
PHP has become one of the Web’s most popular development tools. Many prominent sites and services are built on PHP, from Facebook to the Wordpress blogging package. Applications are now starting to migrate to the more flexible PHP 5 platform while Microsoft has committed to supporting PHP on its new Dynamic Language Runtime, making it a tool for building Silverlight 2.0 applications as well as Web pages. PHP has also developed links with desktop GUI libraries like GTK and QT and is also being used for desktop applications and command line scripting.
The current version of PHP is PHP 5 which considerably improved PHP’s object oriented programming support. Key features include a set of tools for working with remote data and with Web services, as well as tools for working with the popular MySQL database. One interesting feature that can speed up data access in PHP 5 applications is its embedded SQLite database which can be used to cache data from a Web server locally.
PHP developers have a wide choice of development tools. Simple applications can be built using Adobe’s Dreamweaver which supports PHP syntax. For something more ambitious, ActiveState’s Komodo is an IDE designed for dynamic languages and offers PHP development tools alongside Perl, Python and Ruby.
Komodo includes PHP debugging tools with automated configuration features that mean you can debug PHP applications running on a different platform from the IDE. The IDE is based on Mozilla so it’s extensible – you write plug-ins using the same techniques as Firefox extensions. See www.greymatter.com/komodo for details. There is also a version of CodeGear Delphi for PHP available. See http://www.greymatter.com/product/Embarcadero/Delphi-for-PHP/386574 for more information.
Other PHP IDE’s include Zend’s own Zend Studio which handles database connections as well as managing PHP Web services. Zend Studio includes tools to handle application templates which can help with code reuse. It also has tools that help document your applications – something that’s essential when code and design elements interact so closely.
The Eclipse Foundation has also been working on PHP tools which you can find in IDEs like Aptana. The Eclipse PHP development tools include design and layout tools, as well as a debugger.
PHP is often compared to ASP.NET and the two technologies share a common mark-up philosophy and a similar niche in the Web application ecosystem. However that’s as far as they go as PHP’s focus on inline scripting is very different from Microsoft’s code-behind approach. It’s possible to build very complex applications with ASP.NET – but it’s also possible to deliver working Web applications very quickly with PHP.
One of PHP’s strengths is its extensibility. Extensions are written in C and work with PHP’s extension API. You can call extensions from your PHP code and they can be used to work with server and operating system features, as well as linking to popular Internet services like IRC. You can find extensions through the PHP Extension Community Library.
The syntax of a PHP application is relatively easy to understand with statements embedded inside HTML mark-up. PHP statements can be standalone function calls or sections of procedural code. PHP’s object model was rewritten for PHP 5 and now supports handle-based object references, making it easier to access object data and reducing memory overheads. Objects can have private variables and there are tools for handling inheritance and cloning objects. PHP also now supports exception handling so you can handle application problems gracefully.
An issue facing PHP developers is debugging page code. PHP applications are interpreted and run on the server so there can be issues with debugging.
How to shoot yourself in the foot in PHP:
# You shoot yourself in the foot with a gun made with pieces from 300 other guns.