![]() PHP_CompatInfo : The Definitive Guide
|
Table of Contents
If your file implement code condition that is optional and don't break main goal, such as, for example : if
function_exists
then i do something, else i do something else.
Solution is very easy: You have to specify what function required should be considered as optional.
Suppose we have to detect which PHP version we need to run this chunk of script named "errorHandler.php". With standard behavior, PHP_CompatInfo returns PHP 4.3.0 (because
debug_backtrace
came with version 4.3.0). So, if we ignore function
debug_backtrace
to find out the minimum version, we will get the real and true result.
<?php // ... if (function_exists('debug_backtrace')) { $backtrace = debug_backtrace(); } else { $backtrace = false; } // ... ?>
We will use another very simple detection script. Have a look on options array given as second parameter (here is the magic).
<?php require_once 'PHP/CompatInfo.php'; $info = new PHP_CompatInfo(); $path_to_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'errorHandler.php'; $options = array('ignore_functions' => array('debug_backtrace')); $res = $info->parseFile($path_to_file, $options); echo '<pre>'; var_dump($res); echo '</pre>'; ?>
And the raw results are :
array(4) { ["max_version"]=> string(0) "" ["version"]=> string(5) "3.0.7" ["extensions"]=> array(0) { } ["constants"]=> array(0) { } }
pcicmd command used files to specify list of values on
--ignore-
switchs.
pcicmd -f \wamp\www\pci\errorHandler.php -in \wamp\www\pci\functions.txt
![]() |
Note |
---|---|
functions.txt is a simple text file with one line by PHP function that should be ignore. In our example, content is one line with value :
debug_backtrace |
And result give:
+------------------------+---------+------------+------------------+ | File | Version | Extensions | Constants/Tokens | +------------------------+---------+------------+------------------+ | [...]\errorHandler.php | 3.0.7 | | | +------------------------+---------+------------+------------------+
PHP_CompatInfo : The Definitive Guide | v 1.4.0 : September 27, 2006 |