PHP_CompatInfo::parseFile
Synopsis
Array PHP_CompatInfo::parseFile (
string $file
, array $options
= array()
)
Description
Parse a file for its compatibility info
Parameter
-
string
$file
-
Path of File to parse
-
array
$options
-
An array of options where:
-
debug Contains a boolean to control whether extra ouput is shown.
-
ignore_functions Contains an array of functions to ignore when calculating the version needed.
-
ignore_constants Contains an array of constants to ignore when calculating the version needed.
-
ignore_extensions Contains an array of php extensions to ignore when calculating the version needed.
-
ignore_versions Contains an array of php versions to ignore when calculating the version needed.
-
ignore_functions_match Contains an array of function patterns to ignore when calculating the version needed.
-
ignore_extensions_match Contains an array of extension patterns to ignore when calculating the version needed.
-
ignore_constants_match Contains an array of constant patterns to ignore when calculating the version needed.
-
Throws
throws no exceptions thrown
See
Since
since version 0.7.0 (2004-03-09)
Note
This function can not be called statically.
Return value
array - a hash which contains information keys:
ignored_functions
,
ignored_extensions
,
ignored_constants
,
max_version
,
version
,
extensions
,
constants
,
tokens
,
cond_code
Example
Suppose we have to parse source code like this one, named "conditional.php" :
<?php
// PHP 4.0.0 : __FILE__
// PHP 4.0.6 : DIRECTORY_SEPARATOR
// PHP 4.0.7 : version compare
// PHP 4.3.0 : ob_get_clean
// PHP 4.3.0 : debug_backtrace
// PHP 4.3.10 and 5.0.2 : PHP_EOL
// PHP 5.0.0 : simplexml_load_file
// PHP 5.1.1 : DATE_W3C
if (!defined('DIRECTORY_SEPARATOR')) {
define('DIRECTORY_SEPARATOR',
strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? '\\' : '/'
);
}
if (function_exists('debug_backtrace')) {
$backtrace = debug_backtrace();
} else {
$backtrace = false;
}
if (function_exists('simplexml_load_file')) {
$xml = simplexml_load_file('C:\php\pear\PHP_CompatInfo\scripts\version.xml');
}
if (version_compare(phpversion(), '5.0.0', '<')) {
include_once 'PHP/Compat.php';
PHP_Compat::loadFunction('ob_get_clean');
PHP_Compat::loadConstant('PHP_EOL');
}
echo "Hello World" . PHP_EOL;
$ds = DIRECTORY_SEPARATOR;
$fn = dirname(__FILE__) . $ds . basename(__FILE__);
echo "You have run file : $fn at " . date(DATE_W3C) . PHP_EOL;
?>
<?php
require_once 'PHP/CompatInfo.php';
$pci = new PHP_CompatInfo();
$input = 'conditional.php';
$options = array('ignore_functions' => array('simplexml_load_file'),
'ignore_constants' => array('DATE_W3C')
);
$res = $pci->parseFile($input, $options);
#var_export($res); // no need since PCI 1.8.0
?>
We get such result.
array ( 'ignored_functions' => array ( 0 => 'simplexml_load_file', ), 'ignored_extensions' => array ( ), 'ignored_constants' => array ( 0 => 'DATE_W3C', ), 'max_version' => '', 'version' => '4.3.10', 'classes' => array ( ), 'extensions' => array ( 0 => 'date', ), 'constants' => array ( 0 => 'DATE_W3C', 1 => 'DIRECTORY_SEPARATOR', 2 => 'FALSE', 3 => 'PHP_EOL', 4 => 'PHP_OS', 5 => '__FILE__', ), 'tokens' => array ( ), 'cond_code' => array ( 0 => 5, ), )
That means php simple_load_file() function and constant DATE_W3C were ignored from scope, and PHP version minimum to run is 4.3.10 (in such condition)
Of course it is impossible to run such script with only PHP 4.3.10 because usage of DATE_W3C constant is not conditionned.