Checking for installed PEAR module in PHP

PHP has the intention to make PEAR a repository of common libraries similar to CPAN in Perl. This still isn’t the case though. Every time I’ve used PEAR it is a bit kludgy. There should be some support functions as part PEAR itself to do simple operations through php scripts.

For example I wrote a report generation class for Testlink that uses Spreadsheet_Excel_Writer and I wanted to check that this dependency is met during installation. This isn’t as clear cut to do as it should be though. I wasn’t able to find any standard way in documentation for how to check if a PEAR module is actually even installed. First I tried to use the built in is_file() function in php. This doesn’t honor the include_path though so it isn’t very useful with PEAR. So I ended up just doing an include_once() for the module. This isn’t very clean though as it throws a really ugly error for the user if they have error reporting turned on in their PHP configuration.

So here’s to hoping that PHP and PEAR will someday work together in a more clean way. I would think this would be a very common operation for any project that relies on PEAR modules. Apparently it isn’t though.