Revision [8927]
This is an old revision of CompatibilityCode made by JavaWoman on 2005-06-07 19:01:21.
Compatibility Code
See also:
Compatibility code is code that serves to "hide" differences in coding to accommodate different versions, such as different PHP versions or different MySQL versions. By providing compatibility code with a public interface we can maintain a clean and simple API while dealing with version differences automatically.Different types of compatibility code
Compatibility code can be classified into three kinds, depending on what kind of differences we are hiding; the aim is always to hide complexity from calling code:
Classification
Missing functions
- Code to compensate for PHP functions that may be missing in older versions; this allows (almost) equivalent functionality when Wikka is running on an older PHP version
- Code to compensate for PHP MySQL functions that may be be available only for a newer MySQL version than is installed; this allows for (almost) equivalent functionality when Wikka is using an older MySQL version
Hiding decision logic
- Code that decides which of two possible functions or methods to call depending on PHP or MySQL version installed; by wrapping such decision logic in a single method, the version-dependent decision logic can be hidden with single API
Configuration
- Code that compensates for differences in PHP configuration that may not be under the control of the WikiAdmin or may not be to changed in order not to break other PHP applications.
Compatibility code in Wikka 1.1.6.0
Wikka 1.1.6.0 already has some compatibility code in place, but it could do better... See below for some (proposed) new additions.
mysql_real_escape_string()
Classification
Missing function.Code
The function mysql_real_escape_string() is available in PHP as of version 4.3; Wikka specifies PHP 4.1.0 as minimum PHP version so we need to provide a (near) equivalent for this.The code is found near the start of wikka.php:
- {
- {
- }
- }
Magic quotes
Classification
ConfigurationCode
PHP may be configured to use "magic quotes". When magic_quotes are on, all ' (single-quote), " (double quote), \ (backslash) and NUL's are escaped with a backslash automatically for GPC (Get/Post/Cookie) operations. To avoid having to check for these backslashes in every string we get via cookies or POST and GET requests the following code turns off magic quotes and removes them where found, so any further code does not have to deal with them. The code is (currently) found near the end of wikka.php:- // workaround for the amazingly annoying magic quotes.
- function magicQuotesSuck(&$a)
- {
- {
- foreach ($a as $k => $v)
- {
- magicQuotesSuck($a[$k]);
- else
- }
- }
- }
- {
- magicQuotesSuck($_POST);
- magicQuotesSuck($_GET);
- magicQuotesSuck($_COOKIE);
- }
In a future version this would be better placed together with other compatibility code near the start and maybe get a more "polite" name. :)
Proposed new compatibility code
This is compatibility code needed for or used used by new code development presented on this site.
CategoryDevelopmentCore