You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.0 KiB

20 years ago
20 years ago
  1. Updating your script to PHP6
  2. ============================
  3. This document attempts to describe portions of PHP that changed or
  4. disapeared in PHP6 and the best practices for upgrading existing
  5. applications to support PHP6.
  6. 1. Language
  7. 1.1 Functions and function aliases
  8. 1.2 Register globals
  9. 1.3 Magic quotes
  10. 1.4 Register long arrays ($HTTP_*_VARS)
  11. 1.5 ZE1 compatibility mode
  12. 1.6 dl() function
  13. 1.7 E_ALL and E_STRICT constants
  14. 1.8 References
  15. 2. Unicode (see README.UNICODE-UPGRADES)
  16. 2. Extensions
  17. 2.1 GD
  18. 1.1 Functions and function aliases
  19. ------------------------------
  20. <TODO: List all arguments order changes, aliases droped in php6...>
  21. 1.2 Register globals
  22. ----------------
  23. For security reasons, register_globals has been removed from php6.
  24. ini_get('register_globals') will always return false.
  25. You can emulate its behavior with some minimum changes in your code.
  26. *DISCLAIMER*
  27. people should get a short-term solution if they are willing to run
  28. an insecure app.
  29. Here is an example to emulate the session related functions and
  30. a snippet to register variables:
  31. $_register_globals_order = strrev(ini_get("variables_order"));
  32. $_register_globals_order_len = strlen($_register_globals_order);
  33. for($_register_globals_i=0;$_register_globals_i<$_register_globals_order_len;$_register_globals_i++) {
  34. switch($_register_globals_order{$_register_globals_i}) {
  35. case "E":
  36. extract($_ENV, EXTR_REFS|EXTR_SKIP);
  37. break;
  38. case "G":
  39. extract($_GET, EXTR_REFS|EXTR_SKIP);
  40. break;
  41. case "P":
  42. extract($_POST, EXTR_REFS|EXTR_SKIP);
  43. break;
  44. case "C":
  45. extract($_COOKIE, EXTR_REFS|EXTR_SKIP);
  46. break;
  47. case "S":
  48. extract($_SERVER, EXTR_REFS|EXTR_SKIP);
  49. break;
  50. }
  51. }
  52. unset($_register_globals_order, $_register_globals_order_len, $_register_globals_i);
  53. function session_register($mixed) {
  54. static $started;
  55. if(!isset($started) || session_id() === "") {
  56. session_start();
  57. $started = true;
  58. }
  59. $array = func_get_args();
  60. foreach($array as $mixed) {
  61. if(is_scalar($mixed)) {
  62. $_SESSION[$mixed] =& $GLOBALS[$mixed];
  63. }
  64. elseif(is_array($mixed)) {
  65. foreach($mixed as $name) {
  66. $ok = session_register($name);
  67. if(!$ok) {
  68. return false;
  69. }
  70. }
  71. }
  72. else {
  73. return false;
  74. }
  75. }
  76. return true;
  77. }
  78. function session_is_registered($name) {
  79. if(is_scalar($name)) {
  80. return isset($_SESSION[$name]);
  81. }
  82. return false;
  83. }
  84. function session_unregister($name) {
  85. if(isset($_SESSION[$name]) && is_scalar($name)) {
  86. unset($_SESSION[$name]);
  87. return true;
  88. }
  89. return false;
  90. }
  91. 1.3 Magic quotes
  92. ------------
  93. 1.4 Register long arrays ($HTTP_*_VARS)
  94. -----------------------------------
  95. register_long_arrays and the long versions of super globals had been removed.
  96. PHP will emit E_CORE_ERROR during PHP startup if it would detect
  97. register_long_arrays setting.
  98. You can emulate long arrays by including the following file:
  99. <?php
  100. if (!ini_get('register_long_arrays')) {
  101. $HTTP_POST_VARS =& $_POST;
  102. $HTTP_GET_VARS =& $_GET;
  103. $HTTP_COOKIE_VARS =& $_COOKIE;
  104. $HTTP_SERVER_VARS =& $_SERVER;
  105. $HTTP_ENV_VARS =& $_ENV;
  106. $HTTP_FILES_VARS =& $_FILES;
  107. }
  108. ?>
  109. 1.5 ZE1 compatibility mode
  110. ----------------------
  111. ZE1 compatibility mode (PHP4 object model) was introduced to migrate from PHP4
  112. to PHP5 in an easier way, but it never keeped 100% compatibility.
  113. It is completly removed in PHP6, and there is no way to emulate it.
  114. Applications should assume PHP5/PHP6 object model.
  115. 1.6 dl() function
  116. -------------
  117. Now dl() function is supported only in CLI, CGI and EMBED SAPI.
  118. There is no way to emulte it. You can just check if dl() is supported by SAPI:
  119. <?php
  120. if (!function_exists("dl")) {
  121. die("dl() function is required\n!");
  122. }
  123. ?>
  124. 1.7 E_ALL and E_STRICT constants
  125. ----------------------------
  126. Now E_ALL error reporting mask includes E_STRICT.
  127. You can filter E_STRICT error messages using the following code:
  128. <?php
  129. error_reporting(error_reporting() & ~E_STRICT);
  130. ?>
  131. 1.8 References
  132. ----------
  133. <TODO: Derick plans to clean the reference mess in php6>
  134. 2.1 GD
  135. <TODO: gd2/ft2 only, functions droped>