Revision [16673]

This is an old revision of CompatibilityCode made by EvtOux on 2007-05-31 10:34:50.

 

Compatibility Code


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 the complexity of working around differences from calling code that needs the functionality:

Classification

Missing functions
Hiding decision logic
Configuration

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:
  1. if ( ! function_exists("mysql_real_escape_string") )
  2. {
  3.     function mysql_real_escape_string($string)
  4.     {
  5.         return mysql_escape_string($string);
  6.     }
  7. }


This clearly shows the basic pattern for "missing function" compatibility code:
This ensures that the intended function can be called as normal: if the function does not exist in the current installation, the compatibility code will kick in.

Note that mysql_escape_string() is not exactly equivalent with mysql_real_escape_string(); possibly the code here could be extended a bit to provide better compaitibilty.

Magic quotes


Classification
Configuration

Code
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:
%%(php;1029) workaround for the amazingly annoying magic quotes.
function magicQuotesSuck(
There are 4 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki