Chapter 21. Software Engineering

Introduction

Typing out the expressions that form your computer program is only the beginning of building a healthy software system. This chapter discusses what should happen after you’ve written your initial code—tools for debugging and testing your software.

Using a Debugger Extension explores the use of Xdebug, an open source PHP extension that allows for line-by-line debugging in real time.

Recipes , , and explore the world of unit testing in PHP, and show you how to turn your fixed bugs into a test suite that can help you ensure that once a bug is fixed, it stays fixed.

Setting Up a Test Environment introduces you to easy ways to set up a testing environment on your local computer, so that you can work in a sandbox environment without fear of breaking a production website while you’re trying to determine what’s gone wrong.

Lastly, Using the Built-in Web Server explores the built-in web server that’s part of PHP 5.4.0 and later.

Using a Debugger Extension

Problem

You want to debug your scripts interactively during runtime.

Solution

Use the Xdebug extension. When used along with an Xdebug-capable IDE, you can examine data structure; set breakpoints; and step into, out of, or over sections of code interactively.

Discussion

This recipe focuses on Xdebug’s interactive debugging capability. To follow along, you need to be able to compile and install a Zend extension, which means permissions to edit php.ini on your system. PHP’s dl() extension-loading ...

Get PHP Cookbook, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.