Page 1 of 1

version_compare strangeness

Posted: Sun Dec 16, 2007 1:22 pm
by Echilon
feyd | Please use

Code: Select all

,

Code: Select all

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?

Code: Select all

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.


feyd | Please use

Code: Select all

,

Code: Select all

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]

Posted: Sun Dec 16, 2007 1:34 pm
by Benjamin
Does it product the same results without the operator?

Posted: Sun Dec 16, 2007 2:08 pm
by feyd
There's a space in the session variable making them not equal.

Posted: Mon Dec 17, 2007 3:11 am
by Echilon
feyd wrote:There's a space in the session variable making them not equal.
Good eyesight, this had been illuding me for ages, then someone on IRC suggested trimming the strings.

Thanks for the help. :)

Posted: Mon Dec 17, 2007 4:05 am
by Benjamin
I don't see a space anywhere.

+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'"

Posted: Mon Dec 17, 2007 9:26 am
by feyd
astions wrote:I don't see a space anywhere.

+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.

Posted: Mon Dec 17, 2007 10:11 am
by Kieran Huggins
Yeah, but what number am I thinking of?

Posted: Mon Dec 17, 2007 10:25 am
by John Cartwright
Kieran Huggins wrote:Yeah, but what number am I thinking of?
44?

Posted: Mon Dec 17, 2007 10:30 am
by Kieran Huggins
ZOMG!

It seems that feyd has some competition for this year's "most psychic" award!