PHP userland backwards compatibility layer that emulates PHP 5.5+ core functions.

⌈⌋ ⎇ branch:  upgrade.php


Check-in [101b00995c]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Workaround for .prefixed version having code blocks trailing } stripped on !defined() blocks
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 101b00995c07ebb5b1a73f2a73558db8a472e693
User & Date: mario 2012-08-16 00:05:27
Context
2013-12-17
03:38
Add PHP5.5 boolval, array_column, json_last_error_msg and some more JSOL-extensions to json_decode check-in: c787a0cc27 user: mario tags: trunk
2012-08-16
00:05
Workaround for .prefixed version having code blocks trailing } stripped on !defined() blocks check-in: 101b00995c user: mario tags: trunk
2012-02-16
21:14
Maps short $_SERVER vars onto $HTTP_WHATEVER_VARS for older scripts. check-in: e7ae0ea4ba user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to doc/README.

452
453
454
455
456
457
458

459











460
461
462
463
464
465
466
ChangeLog
---------

v18
  - Anthon Pang contributed mysqli_set_charset() and E_DEPRECATED const
  - Also contrib/safe_serialize and unserialize() implementations by Anthon
  - TMPDIR support for sys_get_temp_dir()

  -












v17
  - new emulation of pspell extension using cmdline tool
  - escaping fixed in json_encode(), ignores utf-8 now
  - a few php 5.2 array functions added
  - str_getcsv, parse_ini_string, quoted_printable_encode
  - inet_pton, inet_ntop, 







>
|
>
>
>
>
>
>
>
>
>
>
>







452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
ChangeLog
---------

v18
  - Anthon Pang contributed mysqli_set_charset() and E_DEPRECATED const
  - Also contrib/safe_serialize and unserialize() implementations by Anthon
  - TMPDIR support for sys_get_temp_dir()
  - gzdecode is now an official PHP 5.4 function.
  - hex2bin
  - session_status
  - zlib_encode / zlib_decode
  - http_redirect, http_response_code, http_send_content_type
  - get_declared_traits (stub), class_uses (stub), get_declared_traits (stub)
  - json_encode: JSON_HEX_AMP, JSON_HEX_TAG, JSON_HEX_APOS, JSON_HEX_QUOT,
    (5.3.3 addition) JSON_NUMERIC_CHECK,
    (5.4.0 addition) JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES
    and JSON_UNESCAPED_UNICODE.
  - json_decode: added flag JSON_BIGINT_AS_STRING, JSON_OBJECT_AS_ARRAY,
    and the non-standard JSON_PARSE_JAVASCRIPT
  - basic basic json_last_error() function

v17
  - new emulation of pspell extension using cmdline tool
  - escaping fixed in json_encode(), ignores utf-8 now
  - a few php 5.2 array functions added
  - str_getcsv, parse_ini_string, quoted_printable_encode
  - inet_pton, inet_ntop, 

Changes to doc/devtools/test-up.

1
2
3
4
5
6
7
#!/bin/sh

echo "generate test-up.php, with if function_exists() removed, all emulations prefixed by up_"

egrep -v '^if [(]!function_exists|^[}]' upgrade.php \
    | perl -pe 'if (/^   function ([\w_\d]+)/) { $save = $1; }; if ($save) { s/$save/up_$save/m; }' \
    > test-up.php






|
1
2
3
4
5
6
7
#!/bin/sh

echo "generate test-up.php, with if function_exists() removed, all emulations prefixed by up_"

egrep -v '^if [(]!function_exists|^[}]' upgrade.php \
    | perl -pe 'if (/^   function ([\w_\d]+)/) { $save = $1; }; if ($save) { s/$save/up_$save/m; }' \
    > upgrade.php.prefixed

Changes to upgrade.php.

44
45
46
47
48
49
50



51
52
53
54


55






56
57
58
59
60
61
62
 *                                   -------------------------- FUTURE ---
 * @group SVN
 * @since future
 *
 * Following functions aren't implemented in current PHP versions, but
 * might already be in CVS/SVN.
 *



 */















/**
 *                                   ----------------------------- 5.4 ---
 * @group 5_4
 * @since 5.4







>
>
>




>
>
|
>
>
>
>
>
>







44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 *                                   -------------------------- FUTURE ---
 * @group SVN
 * @since future
 *
 * Following functions aren't implemented in current PHP versions, but
 * might already be in CVS/SVN.
 *
 * @removed
 *    setcookie2
 *
 */



/**
 *                                   ------------------------ OVERRIDE ---
 *
 */
if (defined("UPGRADEPHP_OVERRIDE") and function_exists("runkit_function_remove")) {
   ini_set("runkit.internal_override", 1);
   runkit_function_rename("json_encode", "php::json_encode");
   runkit_function_rename("json_decode", "php::json_encode");
 }



/**
 *                                   ----------------------------- 5.4 ---
 * @group 5_4
 * @since 5.4
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
 */
if (!defined("JSON_HEX_TAG")) {
   define("JSON_HEX_TAG", 1);
   define("JSON_HEX_AMP", 2);
   define("JSON_HEX_APOS", 4);
   define("JSON_HEX_QUOT", 8);
   define("JSON_FORCE_OBJECT", 16);
}
if (!defined("JSON_NUMERIC_CHECK")) {
   define("JSON_NUMERIC_CHECK", 32);      // 5.3.3
}
if (!defined("JSON_UNESCAPED_SLASHES")) {
   define("JSON_UNESCAPED_SLASHES", 64);  // 5.4.0
   define("JSON_PRETTY_PRINT", 128);      // 5.4.0
   define("JSON_UNESCAPED_UNICODE", 256); // 5.4.0
}
if (!function_exists("json_encode")) {
   function json_encode($var, $options=0, $_indent="") {

      #-- prepare JSON string
      $obj = ($options & JSON_FORCE_OBJECT);
      list($_space, $_tab, $_nl) = ($options & JSON_PRETTY_PRINT) ? array(" ", "    $_indent", "\n") : array("", "", "");
      $json = "$_indent";







|


|




|







730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
 */
if (!defined("JSON_HEX_TAG")) {
   define("JSON_HEX_TAG", 1);
   define("JSON_HEX_AMP", 2);
   define("JSON_HEX_APOS", 4);
   define("JSON_HEX_QUOT", 8);
   define("JSON_FORCE_OBJECT", 16);
 }
if (!defined("JSON_NUMERIC_CHECK")) {
   define("JSON_NUMERIC_CHECK", 32);      // 5.3.3
 }
if (!defined("JSON_UNESCAPED_SLASHES")) {
   define("JSON_UNESCAPED_SLASHES", 64);  // 5.4.0
   define("JSON_PRETTY_PRINT", 128);      // 5.4.0
   define("JSON_UNESCAPED_UNICODE", 256); // 5.4.0
 }
if (!function_exists("json_encode")) {
   function json_encode($var, $options=0, $_indent="") {

      #-- prepare JSON string
      $obj = ($options & JSON_FORCE_OBJECT);
      list($_space, $_tab, $_nl) = ($options & JSON_PRETTY_PRINT) ? array(" ", "    $_indent", "\n") : array("", "", "");
      $json = "$_indent";
784
785
786
787
788
789
790

791
792
793
794
795
796
797
798
799
800
801
802
             "<"  => $options & JSON_HEX_TAG  ? "\\u003C" : "<",
             ">"  => $options & JSON_HEX_TAG  ? "\\u003E" : ">",
             "'"  => $options & JSON_HEX_APOS ? "\\u0027" : "'",
             "\"" => $options & JSON_HEX_QUOT ? "\\u0022" : "\"",
             "&"  => $options & JSON_HEX_AMP  ? "\\u0026" : "&",
         );
         $var = strtr($var, $rewrite);

         if (function_exists("iconv") && ($options & JSON_UNESCAPED_UNICODE) == 0) {
            $var = preg_replace("/[^\\x{0000}-\\x{007F}]/ue", "'\\u'.current(unpack('H*', iconv('UTF-8', 'UCS-2BE', '$0')))", $var);
         }
         if ($options & 0x8000) {//@COMPAT: for fully-fully-compliance
            $var = preg_replace("/[\000-\037]/", "", $var);
         }
         $json = '"' . $var . '"';
      }

      #-- basic types
      elseif (is_bool($var)) {
         $json = $var ? "true" : "false";







>

|
<
<
<







795
796
797
798
799
800
801
802
803
804



805
806
807
808
809
810
811
             "<"  => $options & JSON_HEX_TAG  ? "\\u003C" : "<",
             ">"  => $options & JSON_HEX_TAG  ? "\\u003E" : ">",
             "'"  => $options & JSON_HEX_APOS ? "\\u0027" : "'",
             "\"" => $options & JSON_HEX_QUOT ? "\\u0022" : "\"",
             "&"  => $options & JSON_HEX_AMP  ? "\\u0026" : "&",
         );
         $var = strtr($var, $rewrite);
         //@COMPAT control chars should probably be stripped beforehand, not escaped as here
         if (function_exists("iconv") && ($options & JSON_UNESCAPED_UNICODE) == 0) {
            $var = preg_replace("/[^\\x{0020}-\\x{007F}]/ue", "'\\u'.current(unpack('H*', iconv('UTF-8', 'UCS-2BE', '$0')))", $var);



         }
         $json = '"' . $var . '"';
      }

      #-- basic types
      elseif (is_bool($var)) {
         $json = $var ? "true" : "false";
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
if (!defined("JSON_ERROR_NONE")) {
   define("JSON_ERROR_NONE", 0);
   define("JSON_ERROR_DEPTH", 1);
   define("JSON_ERROR_STATE_MISMATCH", 2);
   define("JSON_ERROR_CTRL_CHAR", 3);
   define("JSON_ERROR_SYNTAX", 4);
   define("JSON_ERROR_UTF8", 5);
}
if (!function_exists("json_last_error")) {
   function json_last_error() {
       global ${'.json_last_error'}; 
       return ${'.json_last_error'}; // gives a notice if json_decode was never invoked before (no status constant for that)
   }
}








|







1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
if (!defined("JSON_ERROR_NONE")) {
   define("JSON_ERROR_NONE", 0);
   define("JSON_ERROR_DEPTH", 1);
   define("JSON_ERROR_STATE_MISMATCH", 2);
   define("JSON_ERROR_CTRL_CHAR", 3);
   define("JSON_ERROR_SYNTAX", 4);
   define("JSON_ERROR_UTF8", 5);
 }
if (!function_exists("json_last_error")) {
   function json_last_error() {
       global ${'.json_last_error'}; 
       return ${'.json_last_error'}; // gives a notice if json_decode was never invoked before (no status constant for that)
   }
}