PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
I'm having problems getting version_compare to work. I have a constant ([b]IZ_MINVER[/b]) and a variable ([b]$_SESSION['backupmeta']['izver'][/b]). They're both in the format #.#.#, but version compare either always evaluates to true, or always to true, regardless of what version numbers are fed into it. I've tried so many variations, does anyone have any idea why this isn't working?
echo IZ_MINVER.':'.$_SESSION['backupmeta']['izver'].':'.(version_compare((string)$_SESSION['backupmeta']['izver'],(string)IZ_MINVER,"lt") ? 'true':'false');
if(version_compare((string)$_SESSION['backupmeta']['izver'],(string)IZ_MINVER,"lt")) {
// this is executed
} else {
//this should be executed, because the versions are equal.
}
Produces the output '2.8.8:2.8.8 :true'. But it should return 0, since they're equal.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
+1 @ feyd if you knew from past experience that this was the cause
-1 @ the op for posting inaccurate data "'2.8.8:2.8.8 :true'"
I knew from past experience that any variance, printable or not, will cause a difference in comparisons. Since the quoted output had a space in it and the code wouldn't have added a space the logical conclusion was that a space was in the string.