PEAR packager tries to be too smart

When trying to PEAR-package MidCOM components with our new pear-package.php utility I ran into this error message:

Error: PHP5 packages must be packaged by php 5 PEAR

Now, it seems that the PEAR 1.x packager tries to be a bit too smart and sniff if files contain PHP5 OOP features like abstract or interface classes. That is all good and well, except that the packager doesn’t really parse the PHP code, it just looks for words like abstract in the file.

This taken into account, guess what happens with code like this (coming from Midgard’s MetaWebLog API interface):

if ($key == "mt_excerpt") {
	$article->abstract = $value->scalarval();

A quick fix for this is to edit the PEAR/Common.php file of your installation and comment out the following:

if (version_compare(zend_version(), '2.0', '<')) {
    if (in_array(strtolower($data),
        array('public', 'private', 'protected', 'abstract',
              'interface', 'implements', 'clone', 'throw')
             )) {
        PEAR::raiseError('Error: PHP5 packages must be packaged by php 5 PEAR');
        return false;

This should be quite safe to do, as MidCOM doesn’t run on PHP5 yet, and so can’t contain any PHP5 files.

No idea if PEAR 1.4 fixes this.

Updated 14:58: The MidCOM packages themselves work now. Pretty cool! See my posting to dev.

Updated 2005-12-27: The decision has been made to package using PEAR 1.4 only. Read the mRFC 0021 for details.

Read more Midgard posts.