![]() PHP_CompatInfo : The Definitive Guide
|
If you read analogous Basic detection chapter, you have certainly noticed that detection of HTML_AJAX 0.5.0 distribution directories gave result PHP 5.0.0. We expect to have PHP minimum 4.2.1
Why such version. If we have a look on basic raw result (array) we could found two files with version 5.0.0 : The first one is
["c:\pear\html\HTML_Ajax-0.5.0\examples\support\xml.class.php"]=> array(4) { ["max_version"]=> string(0) "" ["version"]=> string(5) "5.0.0" ["extensions"]=> array(1) { [0]=> string(6) "domxml" } ["constants"]=> array(0) { } }
If you have a cursory source review, you will see that this file is an alternative to PHP 4 Dom XML extension with new native PHP 5 class DOMDocument.
![]() |
Tip |
---|---|
To solve this situation, you can ignore this optional (example) file, or simply ignore conditional function call to
file_put_contents (came with PHP 4.3.0)
<?php $options = array('ignore_files' => array('C:\PEAR\HTML\HTML_AJAX-0.5.0\examples\support\xml.class.php') ); ?> |
The second file is :
["c:\pear\html\HTML_Ajax-0.5.0\AJAX.php"]=> array(4) { ["max_version"]=> string(0) "" ["version"]=> string(5) "5.0.0" ["extensions"]=> array(3) { [0]=> string(4) "pcre" [1]=> string(4) "curl" [2]=> string(7) "sockets" } ["constants"]=> array(0) { } }
If you have a cursory source review, you will find easily condition code switch around PHP 5 native functions
set_exception_handler
, and
restore_exception_handler
.
![]() |
Tip |
---|---|
To solve this situation, you only need to ignore these functions with :
<?php $options = array('ignore_functions' => array('set_exception_handler', 'restore_exception_handler') ); ?> |
Even with these two fixes, PHP_CompatInfo still give wrong results. If we continue to check files list, we will find an example script "C:\PEAR\HTML\HTML_AJAX-0.5.0\examples\support\xml.class.php" with native
file_get_contents
(came with PHP version 4.3.0).
![]() |
Tip |
---|---|
Ignore all optional files such as example scripts. |
and the main class file (AJAX.php) with two native PHP 4.3.0 functions
file_get_contents
, and
stream_context_create
. But to run this chunk of code you need at least PHP 5.0.0, see if-condition few lines backward with
version_compare
.
![]() |
Tip |
---|---|
Ignore both functions
file_get_contents , and
stream_context_create .
|
Here is now the full detection script.
<?php require_once 'PHP/CompatInfo.php'; $info = new PHP_CompatInfo(); $path_to_dir = 'c:\pear\html\HTML_Ajax-0.5.0'; $options = array('ignore_functions' => array('set_exception_handler', 'restore_exception_handler', 'file_get_contents', 'stream_context_create'), 'ignore_files' => array('C:\PEAR\HTML\HTML_AJAX-0.5.0\examples\support\xml.class.php') ); $res = $info->parseDir($path_to_dir, $options); echo '<pre>'; var_dump($res); echo '</pre>'; ?>
And a chunk of raw results we got :
array(60) { ["ignored_files"]=> array(1) { [0]=> string(59) "c:\pear\html\HTML_Ajax-0.5.0\examples\support\xml.class.php" } ["max_version"]=> string(0) "" ["version"]=> string(5) "4.2.1" ["extensions"]=> array(6) { [0]=> string(8) "mbstring" [1]=> string(4) "pcre" [2]=> string(6) "domxml" [3]=> string(4) "curl" [4]=> string(7) "sockets" [5]=> string(7) "session" } ["constants"]=> array(1) { [0]=> string(8) "__FILE__" } [... more ...] }
It means that we need at least PHP 4.2.1 to run HTML_Ajax 0.5.0 with PHP extensions mbstring, pcre, domxml, curl, sockets, session loaded.
If we try again to detect the same distribution untar directory, the command to run will be:
pcicmd -d c:\pear\html\HTML_Ajax-0.5.0 -in \wamp\www\pci\functions.txt
![]() |
Note |
---|---|
File "functions.txt" contains 5 lines, one for each function to ignore: set_exception_handler, restore_exception_handler, file_get_contents, file_put_contents, stream_context_create |
And chunk of results give:
+----------------------------------+---------+------------+------------------+ | Path | Version | Extensions | Constants/Tokens | +----------------------------------+---------+------------+------------------+ | [...]\* | 4.2.1 | mbstring | __FILE__ | | | | pcre | | | | | domxml | | | | | curl | | | | | sockets | | | | | session | | +----------------------------------+---------+------------+------------------+ | [...]\examples\xml_usage.php | 3.0.0 | | | +----------------------------------+---------+------------+------------------+ | [...]\examples\xmlserver.php | 3.0.0 | | | +----------------------------------+---------+------------+------------------+ | [...]\examples\tests\ (+) | 3.0.0 | | | | test_speed.php | | | | +----------------------------------+---------+------------+------------------+ [... more ...] +----------------------------------+---------+------------+------------------+ | [...]\AJAX\Action.php | 4.0.4 | | | +----------------------------------+---------+------------+------------------+
PHP_CompatInfo : The Definitive Guide | v 1.4.0 : September 27, 2006 |