Skip to content

Commit

Permalink
use the in-built version_compare functionality to check php version i…
Browse files Browse the repository at this point in the history
…s valid.
  • Loading branch information
mantis committed Apr 5, 2013
1 parent c53a134 commit 3854c4d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
2 changes: 1 addition & 1 deletion core.php
Expand Up @@ -280,7 +280,7 @@ function __autoload( $p_class ) {
require_api( 'php_api.php' );

# Enforce our minimum PHP requirements
if( !php_version_at_least( PHP_MIN_VERSION ) ) {
if( !(version_compare(PHP_VERSION, PHP_MIN_VERSION ) >= 0 ) ) {
@ob_end_clean();
echo '<strong>FATAL ERROR: Your version of PHP is too old. MantisBT requires PHP version ' . PHP_MIN_VERSION . ' or newer</strong><br />Your version of PHP is version ' . phpversion();
die();
Expand Down
34 changes: 0 additions & 34 deletions core/php_api.php
Expand Up @@ -52,37 +52,3 @@ function php_mode() {

return $s_mode;
}

/**
* Returns true if the current PHP version is higher than the one specified in the given string
* @param string $p_version_string php version string to check
* @return bool
*/
function php_version_at_least( $p_version_string ) {
static $s_cached_version;

if( isset( $s_cached_version[$p_version_string] ) ) {
return $s_cached_version[$p_version_string];
}

$t_curver = array_pad( explode( '.', phpversion() ), 3, 0 );
$t_minver = array_pad( explode( '.', $p_version_string ), 3, 0 );

for( $i = 0;$i < 3;$i = $i + 1 ) {
$t_cur = (int) $t_curver[$i];
$t_min = (int) $t_minver[$i];

if( $t_cur < $t_min ) {
$s_cached_version[$p_version_string] = false;
return false;
}
else if( $t_cur > $t_min ) {
$s_cached_version[$p_version_string] = true;
return true;
}
}

# if we get here, the versions must match exactly so:
$s_cached_version[$p_version_string] = true;
return true;
}

0 comments on commit 3854c4d

Please sign in to comment.