Team LiB
Previous Section Next Section

Why PHP 5?

It's natural that languages continue to develop, and PHP 5 has done just that—its changes represent the next step in the growth and development of the language. There was nothing fundamentally wrong with PHP 4, and in fact the vast majority of this book can be used on servers running PHP 4 and not PHP 5. The changes in PHP 5 revolve around high-level aspects of the language, namely the object model.

If you are coming to PHP from another programming languages, especially a highly structured, specifically object-oriented language, the crossover to a flexible, procedural language that just happens to handle object-oriented programming can be frustrating. But, the ease of use and robustness is one of the reasons new programmers are drawn to PHP in the first place—the learning curve isn't steep, and it gets the job done.

However, this also presents a marketing problem for PHP users working in an enterprise setting. Some Powers That Be might not think PHP is suitable for enterprise-level application development, because it is not a time-tested, structured, object-oriented programming language such as C or even Java. There might not be the time or opportunity for a developer to convince her managers otherwise by showing examples of PHP and C or Java performing the same tasks—if you even can, with the same level of structure, security, reusability, and exception-handling.

From these and other problems came the development path for PHP 5, the main purposes of which were to improve the object model, instill a sense of programming discipline, and specifically design a version of PHP that meets the needs of object-oriented developers and allows them to interface with Java, .NET, and other enterprise-level application frameworks.

But beginning users—likely the primary audience of this book—will not face objects, classes, .NET, or XML-integration their first day on the job. These users simply want a fast, flexible language they can use to create basic, dynamic websites, and PHP 5 still meets that need. Although PHP 5 contains an enhanced internal scripting engine and a vastly improved object-oriented framework, the PHP Group and Zend Technologies recognize and appreciate the roots of PHP and the core group of users who have made it so pervasive. As with PHP 4, PHP 5 does not force you to use the elements of the language you don't need.

Overview of Changes in PHP 5

Because this book does not provide lessons in programming PHP from an object-oriented point of view, this section will not go into detail and show examples of the object model changes in PHP 5. For that, I highly recommend Harry Fuecks' article "PHP5: Coming Soon to a Webserver Near You," at http://www.sitepoint.com/article/1192/. This article contains an outstanding dissection of the object-related changes in PHP 5, and how to implement them.

A few other major features are part of PHP 5, including the appearance of SQLite, an embedded database engine. This is not at all meant to replace a robust database like MySQL, PostgreSQL, or Oracle. Instead, this simple, speedy little database can store database files in both files and memory and thus would be good for something like storing session data and application configuration information—simple INSERTs and SELECTs. Although this book uses MySQL as its database of choice, you can learn more about SQLite in Appendix E, "Using SQLite."

Another change is in the XML arena. PHP 4 used several third-party libraries to control XML parsing and rendering, thus there was no single stable and reliable XML rendering and parsing mechanism. PHP 5 provides one XML library, Gnome's libxml, as the foundation for the DOM extension. This library is very fast and full-featured, and thus a solid foundation on which to rebuild the XML functionality in PHP. You will learn more about working with XML in PHP 5 in Chapter 25, "Working with XML."

Backwards Compatibility with PHP 4

The changelog and PHP manual always indicate when a new implementation will cause problems in previous versions, so at least read the changelog thoroughly if not the manual entries for your favorite functions. However, the vast majority of PHP 5 focuses on additional functionality rather than completely replacing existing elements. If you have learned PHP using PHP 4, you might find that none of your scripts require a rewrite.

Requiring a rewrite and rewriting scripts for the sake of utilizing new functionality are completely different—you might want to rewrite to take advantage of new object-oriented functionality, but you might not have to. If your code is primarily procedural (as with the scripts in this book), there's a better than 95% chance that no rewrites will be necessary.

Similarly, if you cannot install PHP on your own machine for development or product purposes, as outlined in Chapter 3, "Installing PHP," and must use PHP 4, do not fret. Anything taught in this book that doesn't work in PHP 4 is indicated as such.


Team LiB
Previous Section Next Section