Tired of repetitive coding for tasks such as generating web site breadcrumbs? PHP 5 provides a number of interesting ways to reuse your code so you can let the boring stuff take care of itself. This eight-part series will show you how to create helpers to take care of repetitive tasks and free up your precious coding time for the real challenges.
When it comes to speeding up the development of web applications, experienced PHP programmers tend to be rather lazy, and I'm not using that adjective with a negative connotation. Popular concepts like "don't reinvent the wheel" and DRY (short for "don't repeat yourself") help developers avoid creating PHP programs from scratch, while maintaining a high level of control over how their logic is implemented.
Naturally, as you may have guessed, the most direct and simplest application of these concepts is code reuse. This concept can be applied through a variety of custom and third-party libraries, packaged in the form of classes or functions, or a combination of both.
Undoubtedly, the ultimate implementation of code reuse is a full-featured framework. Such frameworks provide developers with a set of well-trusted classes, modules, plug-ins and helpers that permit them to build complex web-based programs very quickly and without suffering premature hair loss.
But, wait a minute! If you reread the previous sentence, you'll notice that I subtly introduced the term "helpers." What are they? Well, if you still haven't coded one on your own, helpers are usually small blocks of reusable code that help programmers to perform certain repetitive tasks.
A helper usually can be structured as one single class or as a set of functions, and the things it does generally aren't as complex as those done by a full-blown library. Common tasks that must be performed over and over again with different projects, such as building portions of a URL, generating web site breadcrumbs and formatting chunks of text, are typical functions of helpers, to cite just a few illustrative examples.
Despite its seeming simplicity, building helpers can be a pretty challenging process, particularly for beginners whom are just starting to implement the object-oriented paradigm in PHP 5. So, in this series of articles, I'm going to introduce you as gently as possible to creating different types of helpers, which hopefully will make you understand the basis of this process and encourage you to create your own.
Now, it's time to get rid of the boring theory and start learning how to build helpers with PHP 5. Let's begin right away!