note 21862 modified in function.version-compare by derick

From: Date: Sun, 01 Jun 2003 14:34:53 +0000
Subject: note 21862 modified in function.version-compare by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-49534@lists.php.net to get a copy of this message
If you wish to use a similar function before version 4.1.0, you can use the following: function minimum_version( $vercheck ) { $minver = explode(".", $vercheck); $curver = explode(".", phpversion()); if (($curver[0] < $minver[0]) || (($curver[0] == $minver[0]) && ($curver[1] < $minver[1])) || (($curver[0] == $minver[0]) && ($curver[1] == $minver[1]) && ($curver[2][0] < $minver[2][0]))) return false; else return true; } if (minimum_version("4.1.0")) { $issue = $_GET['issue']; } This is a good way to write code that works both before and after version 4.1.0, which changed how global predefined variables work. --was-- The above has some logic problems and should actually be: function minimum_version( $vercheck ) { $minver = explode(".", $vercheck); $curver = explode(".", phpversion()); if (($curver[0] < $minver[0]) || (($curver[0] == $minver[0]) && ($curver[1] < $minver[1])) || (($curver[0] == $minver[0]) && ($curver[1] == $minver[1]) && ($curver[2][0] < $minver[2][0]))) return false; else return true; } if (minimum_version("4.1.0")) { $issue = $_GET['issue']; } This is a good way to write code that works both before and after version 4.1.0, which changed how global predefined variables work. http://www.php.net/manual/en/function.version-compare.php

« previous php.notes (#49534) next »