NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP Compatibility and Portability

Tracy tech_learner at yahoo.com
Wed May 28 09:38:09 EDT 2003


may be this can egt things started...
 
http://www.weberdev.com/index.php3?GoTo=get_example.php3?count=3660
Make your PHP 4.1 (or higher) script compatible with PHP 4.0 (still used by some prviders)
 
<?php 
// PHP4 < 4.1 Compatibility 
if (!function_exists('version_compare')) { 
    function version_compare ($a, $b, $c) { 
        return (TRUE); 
    } 
}  
if (version_compare(phpversion(), "4.1.0", "<")) { 
    $_SERVER = $HTTP_SERVER_VARS; 
    $_REQUEST = array_merge ($HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_COOKIE_VARS); 
    $_GET = $HTTP_GET_VARS; 
    $_POST = $HTTP_POST_VARS; 
    $_COOKIE = $HTTP_COOKIE_VARS; 
    $_FILES = $HTTP_POST_FILES; 
    $_SESSION = $HTTP_SESSION_VARS; 
    $_ENV = $HTTP_ENV_VARS; 
} // End PHP4 < 4.1 Compatibility 
?> 

User Comments:
You aren`t REALLY ensuring compatability of an entire script, just the $_SERVER (etc) arrays. 

There is still one LARGE difference however. $_SERVER, $_POST, etc are all superglobal arrays, which means you don`t have to do things like: 

function foo() 
{ 
global $_SERVER; 
} 

In your example, the user would still have to have a global ... statement in any user functions they declared. 

Your example solves a LOT of problems, but not all :)
 
Tracy



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Coming together is a beginning... 
   keeping together is progress... 
      working together is success !!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

---------------------------------
Do you Yahoo!?
Free online calendar with sync to Outlook(TM).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030528/6793add8/attachment.html>


More information about the talk mailing list