12.6. Building Packages

In this section, you explore the PEAR package system from the inside, learning how to build your own packages and how to make the most out of the installer. Following is an example package containing a PHP class, a command-line script, a regression test, and a package description file.

12.6.1. PEAR Example: HelloWorld

This is the minimal example, a single PHP source file implementing a class called HelloWorld:

<?php

/**
 * Hello World class.  The ubiquitous example.
 * @package HelloWorld
 */
class HelloWorld
{
    function HelloWorld($html = true)
    {
        if ($html) {
            print "Hello, World!<br />\n";
        } else {
            print "Hello, World! \n";
        }
    }
}

HelloWorld.php

Here is a command-line script called “hello” for demonstration:

 #!/bin/sh exec ...

Get PHP 5 Power Programming 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.