XF 2.1 PHP check : XenForo 2.1 version ID

Jean-Baptiste

Well-known member
Hello,

To get the version ID for XenForo, you need to call the following static variable :
Code:
\XF::$versionId

I would like to make a conditionnal check, to check if the version is older or equal to 2.1 (I don't care if it's a beta or stable release).

I read the following doc : https://xenforo.com/xf2-docs/dev/add-on-structure/#recommended-version-string-format

Is the following code correct to check if I am using the 2.1 version of XenForo ?
Code:
if(\XF::$versionId > 2001070)

Thanks for the help,

Best regards,
Jean-Baptiste
 
That would be checking for version 2.0.10.

I'll explain how the version ID works as it's useful. It breaks down like this:
  • 2 this is the first point of the version
  • 00 this is the second point of the version
  • 10 this is the third point of the version
  • 7 this is the stability indicator (alpha is 1, beta is 3, RC is 5 and stable is 7)
  • 0 this is mostly unused unless for beta, or RC stability
With that in mind, if you wanted to convert version 2.1.0 (stable) to a version ID then it is:
2 | 01 | 00 | 7 | 0

Or 2.1.0 Beta 5:
2 | 01 | 00 | 3 | 5

Or 2.1.0 Release Candidate 2:
2 | 01 | 00 | 5 | 2

Or some future version like 3.5.2:
3 | 05 | 02 | 7 | 0

So to answer your question directly, if you wanted to check for any version of 2.1.0, we'd probably just recommend checking for version 2.1.0 Beta 1 or above (as that's the earliest release in the wild) which would be:
PHP:
if (\XF::$versionId >= 2010031)
 
This is slightly unrelated, but Chris you just answered a question that I've always had. What do those long version strings stand for?

I always used, let's say, 223 for 2.2.3 lol.

Thank you!
 
Last edited:
This is slightly unrelated, but @Chris you just answered a question that I've always had. What do those long version strings stand for?

I always used, let's say, 223 for 2.2.3 lol.

Thank you!
223 for 2.2.3 is ok, but it becomes awkward for things like beta versions etc. But probably more commonly if you're sticking to some sort of semantic versioning, and version 2.2 ends up having more than 9 bug fix releases, then version 2.2.10 is going to have a version ID of 2210. Is that version 2.21.0? Or version 2.2.10? or version 22.1.0?

Whereas with the pattern we use there's no ambiguity.

2.2.10 = 2021070
2.21.0 = 2210070
22.1.0 = 22100070

etc.
 
That would be checking for version 2.0.10.

I'll explain how the version ID works as it's useful. It breaks down like this:
  • 2 this is the first point of the version
  • 00 this is the second point of the version
  • 10 this is the third point of the version
  • 7 this is the stability indicator (alpha is 1, beta is 3, RC is 5 and stable is 7)
  • 0 this is mostly unused unless for beta, or RC stability
With that in mind, if you wanted to convert version 2.1.0 (stable) to a version ID then it is:
2 | 01 | 00 | 7 | 0

Or 2.1.0 Beta 5:
2 | 01 | 00 | 3 | 5

Or 2.1.0 Release Candidate 2:
2 | 01 | 00 | 5 | 2

Or some future version like 3.5.2:
3 | 05 | 02 | 7 | 0

So to answer your question directly, if you wanted to check for any version of 2.1.0, we'd probably just recommend checking for version 2.1.0 Beta 1 or above (as that's the earliest release in the wild) which would be:
PHP:
if (\XF::$versionId >= 2010031)

Thanks you very much for your reply and patience Chris 👍.
 
Top Bottom