You are here: PHP Version Number Comparison issue « PHP Programming Language « IT news, forums, messages
PHP Version Number Comparison issue

Posted by comp.lang.php on 12/20/05 18:16

I have written several applications that have very specific
functionality that is version-dependent, furthermore, requirements
dictate my apps span multiple versions of PHP.

I have written a function that detects which version of PHP and
ultimately converts it into integer form, however, I am foreseeing a
problem in doing this which I will illustrate to you now:

[PHP]
if (!function_exists('get_php_version_int')) {
/**
* Get PHP version into integer form
*
* @access public
* @return int $phpVersionInt
*/
function get_php_version_int($seedVersion = '') {
$phpVersion = (strlen($seedVersion) > 0) ? str_replace('.', '',
$seedVersion) : str_replace('.', '', phpversion());
return (int)(preg_replace('/^([0-9]+).*$/','$1', $phpVersion));
}
}
echo '5.0.4 > 4.3.11? '. ('5.0.4' > '4.3.11') . ' BUT.. using
get_php_version_int? ' . (get_php_version_int('5.0.4') >
get_php_version_int('4.3.11')) .
'<P> 4.3.11 > 4.3.2? ' . ('4.3.11' > '4.3.2') . ' BUT.. using
get_php_version_int? ' . (get_php_version_int('4.3.11') >
get_php_version_int('4.3.2')) .
'<P> 4.3.2 > 4.1.10? ' . ('4.3.2' > '4.1.10') . ' BUT.. using
get_php_version_int? ' . (get_php_version_int('4.3.2') >
get_php_version_int('4.1.10'));

[/PHP]

Produces the following results:

[Quote]
5.0.4 > 4.3.11? 1 BUT.. using get_php_version_int?

4.3.11 > 4.3.2? BUT.. using get_php_version_int? 1

4.3.2 > 4.1.10? 1 BUT.. using get_php_version_int?
[/Quote]

The first line is correct if the versions are kept as strings but
incorrect if converted to integer. The second line is wrong if the
versions are kept as strings but correct if converted to integer. The
third line is correct if the versions are kept as strings but incorrect
if converted to integer.

My code throughout my apps depends on an integer format for now for
version number comparison using get_php_version_int(). What would you
recommend I do that might be better yet requires the least amount of
code changes?

Thanks
Phil

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация