Gavin Sherry continues his exploration of what makes PHP 5 so special. This month it's exceptional.
Stories by Gavin Sherry
An iterator is a mechanism by which you can traverse the values in some programmatic construct, the most basic being the for() and while() loops. The concept behind these constructs does not map directly to objects, however, as they store a variety of different types of data which may need to be traversed in a user-defined way. The problem is defining what you're iterating through: properties and methods. In PHP 5, the programmer can define (or 'overload') this behaviour.
Thanks to input from people all over the Internet, PHP has been developed at a very fast pace. While this has contributed to PHP's ease of use, it has also led to the language being less than complete - especially when it comes to object orientation.
Last month we looked at PHP's extensive error reporting framework. This month, we'll be looking at customising error reporting, and providing much more information for developers.
By default, PHP generates a lot of helpful information for developers when an error occurs in the execution of a script. This information is much less useful to users, however. In fact, telling users the line number of the error, the function it occurred in, the location of the script on the file system and the exact nature of the error would be considered to compromise the security of the script itself.
Matching patterns in strings is important in just about all Web applications that deal with data. PHP has a large number of pattern matching functions and extensions, tightly integrated into the language itself.
We have looked extensively at manipulating files on the file system. This time we will look at directories, the other major component of conventional file systems.
The PHP column 'PHP file system functions' looked at PHP functions that give developers more information about files and the file system itself. This time, we will expand on this by looking at symbolic links.
In this column, we will look at the range of functions PHP provides for interacting with the file system. At their most basic level, file systems interface storage media - generally hard disk drives - with applications. The most popular file systems in current use rely on the directory and the file as their most elementary concepts.
Over previous tutorials, we have occasionally made use of arrays without going into much detail about exactly what arrays should be used for, which kind of arrays are supported by PHP and the routines the language provides to simplify array usage.
Dates and time form an important part of many sophisticated PHP applications. From simply displaying the date for a user to validating dates and times in user-supplied input, PHP developers have a wealth of functions to solve all manner of problems.
The File Transfer Protocol (FTP) is widely used to transfer files across networks. Utilising it in a PHP script allows you to increase the level of sophistication of your PHP scripts as well as learn more about how FTP works. Before proceeding, get the details of an FTP account to which you have read and write access. For example, most Internet service providers give users an account on their Web servers to host a small amount of data, to which access is generally provided via FTP.
The PHP Extension and Application Repository (PEAR) is an open source structured library of packages for PHP developers. These packages provide routines which solve problems PHP developers regularly face: sending structured e-mail (such as an HTML attachment), interacting with different databases from a single script, error handling, recovery and logging.
The focus of object orientation is the logical grouping of related variables into a generic variable - an object. Before you can create an object, however, you must create a class. A class is a template for an object. The following class, Vehicle, is designed to describe attributes of 'any' vehicle.
As well as being great for generating textual content dynamically, PHP is also useful for dynamically creating images. Using a special PHP extension, we'll explore the possibilities of image creation in this column over the next few columns.