PHP Version Checker

PHP Version Checker is a version checker and code analysis tool to help determine the minimum PHP version and modules / extensions required to execute a given PHP script. It also generates a prerequisite checking function to scan for required dependencies.

The internal mechanism is quite simple: scan for functions and constants and look them up in a table.

Notes:

Download

php_version.php.gz requires PHP 4.2.0 or greater and these extensions: array, dir, errorfunc, filesystem, funchand, info, math, regex, strings, tokenizer, and var. Most of these are built in.

Alternative Software

Check out PHP_CompatInfo for an alternate PHP version checker.

Todo

Usage

Command line syntax: php php_version.php file1.php file2.php ...

Use in a script: test.php - This script generates a check_prereqs function to be included at the beginning of a script.

<?php
  error_reporting
(E_ALL);
  if(isset(
$_FILES['userfile']['tmp_name']) && $_FILES['userfile']['tmp_name'] != '')
  {
    
$_POST['src'] = join(''file($_FILES['userfile']['tmp_name']));
  }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <link rel="stylesheet" href="docs/media/stylesheet.css" />
  <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
</head>
<body>
<h2>Code Check</h2>
<p>Paste your code below and press <b>Check Version</b>.</p>
<form enctype="multipart/form-data" action="test.php" method="post">
  <textarea name="src" rows="20" cols="80"><?php
    
if(isset($_POST['src'])) echo htmlentities($_POST['src']);
  
?></textarea><br />
  <input type="hidden" name="MAX_FILE_SIZE" value="300000" />
  Or, send a file: <input name="userfile" type="file" /><br />
  <input type="submit" value="Check Version"/>
</form>
<?php
  
if(isset($_POST['src']) && $_POST['src'] != '')
  {
    require(
'php_version.php');

    
$v = new php_version();
    
$v->scan_code($_POST['src']);

    echo 
"This code requires PHP {$v->version}.<br />\n";
    if(
count($v->modules))
    {
      echo 
"The following modules are required:<br />\n<ul>";
      foreach(
$v->modules as $module)
      {
        echo 
"<li><a href=\"http://php.net/manual/en/ref.$module.php\">$module</a><br />";
        echo 
"Functions:<br />\n<ul>\n";
        foreach(
$v->functions as $function=>$version)
        {
          if(
$v->find_function_module($function) == $module)
            echo 
"<li>$function</li>\n";
        }
        echo 
"</ul>\n";
        echo 
"Constants:<br />\n<ul>\n";
        foreach(
$v->constants as $constant=>$version)
        {
          if(
$v->find_constant_module($constant) == $module)
            echo 
"<li>$constant</li>\n";
        }
        echo 
"</ul>\n";

        if(
$module == 'info')
        {
          echo 
"Variables:<br />\n<ul>\n";
          foreach(
$v->variables as $variable=>$version)
            echo 
"<li>$variable</li>\n";
          echo 
"</ul>\n";
          echo 
"</li>\n";
        }
      }
      echo 
"</ul>\n";

      echo 
"Code to check prerequisites:<br />\n";
      
highlight_string($v->create_prereq_function());
    }
  }
?>

<script type="text/javascript"><!--
google_ad_client = "pub-8726603957043234";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_page_url = document.location;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

</body>
</html>