note 26681 added to function.phpversion
| From: | matt at rack1 dot php dot net | Date: | Fri, 08 Nov 2002 20:12:55 +0000 |
| Subject: | note 26681 added to function.phpversion | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39195@lists.php.net to get a copy of this message | ||
Interfear's Jun 9 example could benefit from intval, but the following examples have another
problem.
Consider testing version 3.0.19 (hypothetical) against 4.1.0. Given the str_replace(), we end up
with:
if ( 3019 >= 410 )
Which returns true even though the version is much older.
So, something like this should work better:
function check_phpver($version) {
// split versions into arrays.
$test = explode( '.', $version );
$curr = explode( '.', phpversion() );
// do intval conversion.
foreach( $test as $k => $v ) {
$test[$k] = intval($v);
}
foreach( $curr as $k => $v ) {
$curr[$k] = intval($v);
}
// do comparison.
if ( $test[0] < $curr[0] ) { return true; }
if ( $test[0] == $curr[0] && $test[1] < $curr[1] ) { return true; }
if ( $test[0] == $curr[0] && $test[1] == $curr[1] && $test[2] <= $curr[2] ) {
return true;
}
return false;
}
--
http://www.php.net/manual/en/function.phpversion.php
http://master.php.net/manage/user-notes.php?action=edit+26681
http://master.php.net/manage/user-notes.php?action=delete+26681
http://master.php.net/manage/user-notes.php?action=reject+26681