A Web.com Partner

Features of PHP5

This tutorial will explain the new features of PHP5 php

PHP (PHP:Hypertext Preprocessor) was designed to create dynamic web pages, PHP’s principal focus is server-side scripting. While running the PHP parser with a web server and web browser, the PHP model can be compared to other server-side scripting languages such as Microsoft’s ASP.NET system, Sun Microsystems’ JavaServer Pages, mod_perl and the Ruby on Rails framework, as they all provide dynamic content to the client from a web server.

All our hosting plans include PHP 5, which improves on PHP 4 in three major areas:

  • Object-oriented programming
  • MySQL
  • XML

These items have all been completely rewritten, turning them from limitations into star attractions. While these changes alone warrant a new version of PHP, PHP 5 also provides a plethora of other new features.

1. Robust Support for Object-Oriented Programming

PHP 5 offers:

  • Constructors
  • Destructors
  • Public, protected, and private properties and methods
  • Interfaces
  • Abstract classes
  • Class type hints
  • Static properties and methods
  • Final properties and methods
  • A whole suite of magical methods

Additionally, objects are now both assigned and passed by reference instead of by value, so the necessity to liberally sprinkle ampersands throughout your code is no more.

2. A Completely Rewritten MySQL Extension

Many developers power their web sites with MySQL.

Also, the latest versions of MySQL, 4.1 and 5.0, introduce many new features, some of which require significant changes to the extension. As a result, PHP 5 comes with a completely new and improved MySQL extension. Dubbed MySQLi, for MySQL Improved. It offers:

  • Prepared statements
  • Bound input and output parameters
  • SSL connections
  • Multi-query functions

MySQLi even takes advantage of PHP 5’s new object-oriented support to provide an OO interface to MySQL. On top of that, the latest versions of MySQL now enable subselects, transactions, and replication.

3. A Suite of Interoperable XML Tools

PHP 5 fixes the major problems in PHP 4’s XML extensions. While PHP 4 allows you to manipulate XML, its XML tools are only superficially related. Each tool covers one part of the XML experience, but they weren’t designed to work together, and PHP 4 support for the more advanced XML features is often patchy.

Not so in PHP 5.

The new XML extensions:

  • Work together as a unified whole.
  • Are standardized on a single XML library: libxml2.
  • Fully comply with W3 specifications.
  • Efficiently process data.
  • Provide you with the right XML tool for your job.

Additionally, following the PHP tenet that creating web applications should be easy, there’s a new XML extension that makes it simple to read and alter XML documents. The aptly named SimpleXML extension allows you to interact with the information in an XML document as though these pieces of information are arrays and objects, iterating through them with for-each loops, and editing them in place merely by assigning new values to variables.

If you know the document’s format ahead of time, such as when you’re parsing RSS files, REST results, and configuration data, SimpleXML is the way to go.

And if you’re a DOM fan, you’ll be pleasantly surprised with PHP 5’s DOM extension, which is light-years beyond what you’re using in PHP 4.

4. Cleaner Error Handling with Exceptions

PHP 5 offers a completely different model of error checking than what’s available in PHP 4. It’s called exception handling. With exceptions, you’re freed from the necessity of checking the return value of every function. Instead, you can separate programming logic from error handling and place them in adjoining blocks of code.

Exceptions are commonly found in object-oriented languages such as Java and C++. When used judiciously, they streamline code, but when used willy-nilly, they create spaghetti code.

Right now, only a few PHP extensions use exceptions, but they’re slowly being phased in. However, they’re available today for any PHP code you write.

5. A First-Class SOAP Implementation

SOAP is a key component of the fast-growing web services field. This extension lets developers create SOAP clients with or without a Web Services Description Language (WSDL) file, and also implement SOAP servers in PHP.

PHP 4’s SOAP support is only fair. While there are a few SOAP packages, the most mature ones are written in PHP instead of C. Therefore, they are slow, and you have to download and install them yourself.

With PHP 5, there’s finally a usable SOAP extension written in C. Currently, this extension implements most, but not all, of SOAP 1.2. This is a significant improvement over previous C extension, and future pieces will be added in time.

Particularly in comparison with .NET and Java, PHP’s SOAP support has always lagged behind the curve. Whether you love or hate SOAP, PHP needs to offer a first-class SOAP extension, and I’m excited to finally see some momentum in this direction.

x
Chat