PHP_CompatInfo::getVersion
Вернуться к: Getting Results
PHP_CompatInfo::getVersion
Synopsis
mixed PHP_CompatInfo::getVersion ( mixed $file = false , bool $max = false )
Returns the latest parse data source version, minimum and/or maximum
Parameter
- mixed $file
-
(optional) A specific filename or not (FALSE)
- boolean $max
-
(optional) Level with or without contextual data
Return value
returns Null on error or if there were no previous data parsing
Throws
throws no exceptions thrown
Since
since version 1.9.0b1 (2008-11-30)
Note
This function can not be called statically.
Example
Suppose we have to parse source code like this file, 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;
?>
And this second file, named "upload_error.php" :
<?php
$uploadErrors = array(
UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini.",
UPLOAD_ERR_FORM_SIZE => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
UPLOAD_ERR_PARTIAL => "The uploaded file was only partially uploaded.",
UPLOAD_ERR_NO_FILE => "No file was uploaded.",
UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder.",
UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension.",
);
$errorCode = $_FILES["myUpload"]["error"];
if ($errorCode !== UPLOAD_ERR_OK) {
if (isset($uploadErrors[$errorCode])) {
throw new Exception($uploadErrors[$errorCode]);
} else {
throw new Exception("Unknown error uploading file.");
}
}
?>
Script to parse data source, will look like to:
<?php
require_once 'PHP/CompatInfo.php';
$pci = new PHP_CompatInfo('null');
$dir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$input = array($dir . 'conditional.php', $dir . 'upload_error.php');
$options = array('ignore_functions' => array('simplexml_load_file'),
'ignore_constants' => array('DATE_W3C')
);
$pci->parseData($input, $options);
$version = $pci->getVersion();
echo 'GLOBAL version = '. $version . PHP_EOL;
$version = $pci->getVersion($input[0]);
echo basename($input[0]) . ' version = '. $version . PHP_EOL;
$classes = $pci->getClasses();
echo 'ALL Classes = '. implode(',', $classes) . PHP_EOL;
$functions = $pci->getFunctions();
echo 'ALL Functions = '. implode(',', $functions) . PHP_EOL;
$extensions = $pci->getExtensions();
echo 'ALL Extensions required = '. implode(',', $extensions) . PHP_EOL;
$constants = $pci->getConstants();
echo 'ALL Constants required = '. implode(',', $constants) . PHP_EOL;
$tokens = $pci->getTokens();
echo 'ALL Tokens required = '. implode(',', $tokens) . PHP_EOL;
$conditions = $pci->getConditions(false, true);
echo 'ALL Code Conditions = '. $conditions . PHP_EOL;
$conditions = $pci->getConditions($input[1], true);
echo basename($input[1]) . ' conditions = '. $conditions . PHP_EOL;
?>
We have just used the NULL renderer because we want to organize output results, as below:
GLOBAL version = 5.2.0 conditional.php version = 4.3.10 ALL Classes = Exception ALL Functions = basename,date,debug_backtrace,define,defined,dirname,function_exists, phpversion,simplexml_load_file,strtoupper,substr,version_compare ALL Extensions required = date ALL Constants required = DATE_W3C,DIRECTORY_SEPARATOR,FALSE,PHP_EOL,PHP_OS, UPLOAD_ERR_CANT_WRITE,UPLOAD_ERR_EXTENSION,UPLOAD_ERR_FORM_SIZE,UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_NO_FILE,UPLOAD_ERR_NO_TMP_DIR,UPLOAD_ERR_OK,UPLOAD_ERR_PARTIAL,__FILE__ ALL Tokens required = throw ALL Code Conditions = 5 upload_error.php conditions = 0
Вернуться к: Getting Results