Compatibility code with older TYPO3 versions¶
You certainly already wrote compatibility code in your extension to support older versions of TYPO3.
You used to write something like:
if (t3lib_div::int_from_ver(TYPO3_version) >= 4003000) {
// Code for 4.3 and above
} else {
// Code up to 4.2
}
Problem is that t3lib_div::int_from_ver has been moved and renamed as t3lib_utility_VersionNumber::convertVersionNumberToInteger().
Thus you have actually 2 problems here, you don't want to call a deprecated method, namely t3lib_div::int_from_ver to switch to a code compatible with the TYPO3 version you use but at the same point, this very method is the one that allows you to know that you should use the new method t3lib_utility_VersionNumber::convertVersionNumberToInteger().
The official solution is as follows:
$version = class_exists('t3lib_utility_VersionNumber')
? t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version)
: t3lib_div::int_from_ver(TYPO3_version);
if ($version >= 4003000) {
// Code for 4.3 and above
} else {
// Code up to 4.2
}
Update 27.07.2011: A patch has been merged to master and is pending for 4.5: http://forge.typo3.org/issues/28499. Basically, it backports t3lib_utility_VersionNumber to 4.5 and writes usage of t3lib_div::int_from_ver() to deprecation log only starting from 4.7. In short, this means that if you target 4.5.5 and above and do not care anymore for older releases, you can use t3lib_utility_VersionNumber::convertVersionNumberToInteger() and forget about this hocus-pocus.
version_compare()¶
One may say that PHP's version_compare() could be used instead. Well, not really! The problem is that the development version of TYPO3 (currently 4.6-dev) will be interpreted as "before" 4.6.0 and "after" 4.5.99, meaning that you cannot yet write code that looks like that:
if (version_compare(TYPO3_version, '4.6.0', '<')) {
// Won't work for 4.6-dev
}
and writing
if (version_compare(TYPO3_version, '4.5.99', '>')) {
// Code for 4.6 and above
}
is not something I want to write myself because the condition is then not as straightforward to understand as when writing '4.6.0'.