PEAR logo

PHP_CompatInfo : The Definitive Guide

How to catch them with web interface

At the beginning of first version that catch conditional code, there were only 3 options: ignore_functions, ignore_extensions and ignore_constants.

Incovenient with these options, is that you should know the source code to parse, and identify whose functions, extensions or constants to avoid.

Version 1.7.0 of API has introduced the ability to add name patterns to identify all or part of functions, extensions, constants to ignore from parsing. You should use now these options: ignore_functions_match, ignore_extensions_match or ignore_constants_match.

Let's take a look with an example, how it's easy to catch whatever you want to exclude from parsing. We will take again example of PEAR::HTML_CSS 1.5.1 package already seen in advanced directory detection.

  1. <?php
  2. require_once 'PHP/CompatInfo.php';
  3.  
  4. $datasource = '/tmp/HTML_CSS-1.5.1';
  5. $options    = array(
  6.     'ignore_dirs' => array('examples', 'tests'),
  7.     'ignore_functions_match' => array('function_exists', array('/.*/')),
  8.     'ignore_extensions_match' => array('extension_loaded', array('/.*/')),
  9.     'ignore_constants_match' => array('defined', array('/.*/')),
  10.     );
  11.  
  12. $pci = new PHP_CompatInfo();
  13. $pci->parseData($datasource, $options);
  14. ?>

Here we catch all standard conditional code (function_exists, extension_loaded, defined) what match all names (regular expression given by array('/.*/')).

[Tip] Tip

To catch what ever function you want, use preg_match rather than function_exists.

It's also true for extension_loaded and defined

With preg_match you are really free to ignore a single function, a group set or all functions, only by giving the good name pattern.

Example to ignore all functions prefixed by xdebug_ :

  1. <?php
  2. require_once 'PHP/CompatInfo.php';
  3.  
  4. $datasource = '/tmp/HTML_CSS-1.5.1';
  5. $options    = array(
  6.     'ignore_functions_match' => array('preg_match', array('/^xdebug_/')),
  7.     );
  8.  
  9. $pci = new PHP_CompatInfo();
  10. $pci->parseData($datasource, $options);
  11. ?>
PHP_CompatInfo : The Definitive Guide v 1.8.0 : August 1, 2008