Sixteen Best Practices- and Productivity-Related PHP Tutorials

Published On: May 10, 2011 @ 03:04:02pm

I spend a great deal of time writing about Web development, either working on books or writing for online publications such as Developer.com, PHPBuilder.com, JSMag, and TechTarget. So much time in fact that in 2010 I penned more than 130 articles. Many of these articles focused on PHP-specific best practices and productivity, two topics which should resonate closely with anybody involved in building websites for a living.

So I thought it would be useful to compile a list of the sixteen tutorials which touch upon these topics. In this list you’ll find tutorials introducing testing, debugging, advanced object-oriented features, code profiling, security, enforcing coding standards, and more.

Testing Forms in PHP with SimpleTest
Although not as well known as PHPUnit, SimpleTest is an immensely capable framework, having been adopted by popular PHP projects including CakePHP and Drupal. In this tutorial, I’ll show you how to use SimpleTest to automate forms testing.

10 Productive PHP Tools for Testing and Debugging
Despite the general notion that programming is a profession steeped in discipline and rigor, members of the programming community tend to be rather finicky folks who can be very particular when it comes to tooling. Thankfully PHP developers have a great deal to choose from when it comes to testing and debugging tools, and in this article I’ll highlight 10 of my favorites.

Five Popular PHP Templating Engines Worth Checking Out
If you’ve fallen into the trap of mixing your website presentation and logic and are looking for a way out, there are actually quite a few solutions at your disposal. Known as templating engines, these solutions offer the ability to cleanly separate your PHP code from the HTML and other presentational languages (e.g. CSS and JavaScript), improving maintainability and testability. In this article I’ll introduce five of PHP’s most popular templating engines, providing you with a basis for continuing your own investigations.

Three Advanced Object-Oriented PHP Features You Need to Know
In this article I’ll introduce you to three of PHP’s advanced object-oriented features which seem to not have garnered the attention they deserve. The topics discussed here should be useful whether you’re a relative newcomer to object-oriented development and are looking to expand your knowledge, or have a background using languages such as Java or C# and are trying to learn more about what PHP has to offer.

Profiling PHP Code with Xdebug and KCacheGrind
How can one go about determining which parts of an application could be optimized? One common approach involves using a profiler such as Xdebug, which can analyze your code and produce performance reports. These reports can then be reviewed within a profiling visualization tool such as KCacheGrind. In this article I’ll show you how to use Xdebug and KCacheGrind to begin profiling and analyzing your PHP-driven Web applications.

Four Sane Solutions for PHP Debugging
PHP developers have a number of powerful debugging solutions at their disposal. Whether you’re merely inspecting array contents or attempting to determine the status of an Ajax-driven POST response, the four solutions introduced in this article are guaranteed to have an immediate impact on your productivity.

Use the PHP Filter Extension to Validate User Data
With so much potential for distraction, it’s no wonder that developers continue to fall victim to the very same security gaffes that have afflicted the community for well over a decade. Notably, failure to properly validate user input remains the single most serious security issue, with several of the Open Web Application Security Project’s top ten security risks originating directly from this oversight. Fortunately, with PHP 5.2 came an incredibly easy way to ensure that user input fits expectations! Read on to learn how.

Mitigate the Security Risks of PHP System Command Execution
In this tutorial, I’ll show you how to securely execute a variety of system-based commands via a PHP script, demonstrating how to build web applications that can tightly integrate with both the operating system and third-party software.

Enforcing Coding Standards with PHP_CodeSniffer
In light of PHP’s considerable expressive flexibility, how can you actively enforce a coding standard and prevent both yourself and your team members from reverting to bad habits? One great solution called PHP_CodeSniffer is (coincidentally) found in a PEAR package. PHP_CodeSniffer can not only parse PHP code to ensure it meets a particular coding standard but it can also examine your JavaScript and CSS files for potential standards violations.

10 PHP Tricks for Associative Array Manipulation
The associative array—an indispensable data type used to describe a collection of unique keys and associated values—is a mainstay of all programming languages, PHP included. In fact, associative arrays are so central to the task of Web development that PHP supports dozens of functions and other features capable of manipulating array data in every conceivable manner. Such extensive support can be a bit overwhelming to developers seeking the most effective way to manipulate arrays within their applications. In this article, I’ll offer 10 tips that can help you shred, slice and dice your data in countless ways.

Using SPL Iterators in PHP to Interact with Different Data Types
One great way to incorporate more PHP-based object-oriented programming into your applications is through the Standard PHP Library (SPL), a powerful yet largely unknown extension made part of the official PHP language with the PHP 5.0 release. The SPL provides a series of classes which extend the PHP language in numerous ways, offering object-oriented advanced data structures, iterators, and file handlers, among other features. In this tutorial I’ll introduce you to several of my favorite SPL iterators, providing you with the basis from which you can continue your own exploration. Following several examples, I’ll conclude with a brief introduction to other key SPL features.

A Sanity-saving Debugging Solution for Your PHP Development
XDebug is a PHP extension created by longtime PHP core contributor Derick Rethans. Because it is a PHP extension, XDebug can (and does) directly affect certain PHP behaviors in ways that greatly improves the developer’s ability to identify and resolve code errors. After installing XDebug, we’ll work through a few examples that clearly denote these improvements.

Use PHPUnit to Implement Unit Testing in Your PHP Development
If you create web applications that talk to databases, process user input, integrate Ajax functionality, and perform other mission-critical tasks, then it’s crucial that you institute a rigorous testing program—alongside other procedures that may already be in place, such as coding standards and documentation. The PHP community has long had a great testing utility at their disposal known as PHPUnit, and in this tutorial I offer a brief introduction to its benefits.

Using the PEAR Pager Package to Paginate MySQL Results
The PEAR Pager package will not only handle all of the gory details of paginating database results for you, but it can also create a linked navigation list which you can embed into the page as a navigational aide for the user. In this article I’ll show you how to use Pager to easily paginate your database results in a structured and coherent way.

Top 10 phpMyAdmin Tips and Tricks You May Not Know
Despite approaching its 12th birthday, phpMyAdmin is still under active development, with at least one significant version released every year since the project’s inception. In fact even after almost a decade of use I still marvel over discovering features which I had no idea existed. In this article I thought I’d highlight 10 useful phpMyAdmin features which may have escaped you during your daily interaction with this fantastic utility.

Running PHP and Zend Framework Scripts from the Command Line
Did you know it’s possible to run PHP scripts from the command line using its command line interpreter (CLI)? Even though it’s been possible since the PHP 4.3.0 release, you may be completely unaware of this CLI usage unless you employ great tools such as PHPDoc, Phing, or PHPUnit. Running PHP scripts with CLI allows you to leverage your PHP language skills whenever you need to run scripts from the shell.