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

⌈⌋ branch:  upgrade.php


Check-in [d861d4e56d]

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

Overview
Comment:add more defined() checks for undefined constants, fixed bug 7412bf040f in json_encode "0" string/utf8 check.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:d861d4e56d47f37ff821c8ce4ec9fe5a04401804
User & Date: mario 2014-04-24 02:43:02
Context
2014-04-24
02:51
Remove more preg_replace /e with static callbacks check-in: c46171bf99 user: mario tags: trunk
02:43
add more defined() checks for undefined constants, fixed bug 7412bf040f in json_encode "0" string/utf8 check. check-in: d861d4e56d user: mario tags: trunk
02:23
Add ellipse … paramized call support and ->is handler. check-in: ab91327edb user: mario tags: trunk
Changes

Changes to upgrade.php.

406
407
408
409
410
411
412

413
414
415

416
417
418
419
420
421
422
...
429
430
431
432
433
434
435

436
437
438

439
440
441
442
443
444
445
...
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
...
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
...
930
931
932
933
934
935
936


937
938
939
940
941
942
943
944
945
...
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
}

/**
 * Weird constants, not documented in the manual yet, but that's how the function declaration looks.
 *
 */
if (!function_exists("zlib_encode")) {

   define("ZLIB_ENCODING_DEFLATE", 15);
   define("ZLIB_ENCODING_RAW", -15);
   define("ZLIB_ENCODING_GZIP", 31);

   function zlib_encode($data, $method) {
       if ($method == ZLIB_ENCODING_RAW) {
           return gzdeflate($data);
       }
       elseif ($method == ZLIB_ENCODING_DEFLATE) {
           return gzcompress($data);
       }
................................................................................


/**
 * @stub Tests whether a session is established.
 *
 */
if (!function_exists("session_status")) {

   define("PHP_SESSION_DISABLED", 0);
   define("PHP_SESSION_NONE", 1);
   define("PHP_SESSION_ACTIVE", 2);

   function session_status() {
       return (ini_get("session.name") != "") ? PHP_SESSION_DISABLED : 
           (isset($_SESSION) ? PHP_SESSION_ACTIVE : PHP_SESSION_NONE);
   }
}


................................................................................
         #-- enclose into braces or brackets
         $json = $obj ? "{"."$_nl$json$_nl$_indent}" : "[$_nl$json$_nl$_indent]";
      }

      #-- strings need some care
      elseif (is_string($var)) {

         if (utf8_decode($var) != 0) {
            trigger_error("json_encode: invalid UTF-8 encoding in string, cannot proceed.", E_USER_WARNING);
            $var = NULL;
         }
         $rewrite = array(
             "\\" => "\\\\",
             "\"" => "\\\"",
           "\010" => "\\b",
................................................................................
             "'"  => $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";
................................................................................
         ${'.json_last_error'} = JSON_ERROR_UNSUPPORTED_TYPE;
         return;
      }
      
      #-- done
      return($json);
   }


}


/**
 * Parses a JSON (JavaScript value expression) string into a PHP variable
 * (array or object).
 *
 * @compat
 *    Behaves similar to PECL version, but is less quiet on errors.
................................................................................
 *
 * @param   $json string   JSON encoded values
 * @param   $assoc bool    pack data into php array/hashes instead of objects
 * @return  mixed          parsed into PHP variable/array/object
 */
if (!function_exists("json_decode")) {

   define("JSON_OBJECT_AS_ARRAY", 1);     // undocumented
   define("JSON_BIGINT_AS_STRING", 2);    // 5.4.0
   define("JSON_PARSE_JAVASCRIPT", 4);    // unquoted object keys, and single quotes ' strings identical to double quoted, more relaxed parsing

   function json_decode($json, $assoc=FALSE, $limit=512, $options=0, /*emu_args*/$n=0,$state=0,$waitfor=0) {
      global ${'.json_last_error'};
      ${'.json_last_error'} = JSON_ERROR_NONE;

      #-- maximum nesting depth for decoding
      if ($limit < 0) {







>
|
|
|
>







 







>
|
|
|
>







 







|







 







|







 







>
>
|
|







 







|
|
|







406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
...
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
...
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
...
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
...
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
...
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
}

/**
 * Weird constants, not documented in the manual yet, but that's how the function declaration looks.
 *
 */
if (!function_exists("zlib_encode")) {
   if (!defined("ZLIB_ENCODING_DEFLATE")) {
       define("ZLIB_ENCODING_DEFLATE", 15);
       define("ZLIB_ENCODING_RAW", -15);
       define("ZLIB_ENCODING_GZIP", 31);
   }
   function zlib_encode($data, $method) {
       if ($method == ZLIB_ENCODING_RAW) {
           return gzdeflate($data);
       }
       elseif ($method == ZLIB_ENCODING_DEFLATE) {
           return gzcompress($data);
       }
................................................................................


/**
 * @stub Tests whether a session is established.
 *
 */
if (!function_exists("session_status")) {
   if (!defined("PHP_SESSION_DISABLED")) {
       define("PHP_SESSION_DISABLED", 0);
       define("PHP_SESSION_NONE", 1);
       define("PHP_SESSION_ACTIVE", 2);
   }
   function session_status() {
       return (ini_get("session.name") != "") ? PHP_SESSION_DISABLED : 
           (isset($_SESSION) ? PHP_SESSION_ACTIVE : PHP_SESSION_NONE);
   }
}


................................................................................
         #-- enclose into braces or brackets
         $json = $obj ? "{"."$_nl$json$_nl$_indent}" : "[$_nl$json$_nl$_indent]";
      }

      #-- strings need some care
      elseif (is_string($var)) {

         if (!preg_match("/^.+$/su", $var)) {
            trigger_error("json_encode: invalid UTF-8 encoding in string, cannot proceed.", E_USER_WARNING);
            $var = NULL;
         }
         $rewrite = array(
             "\\" => "\\\\",
             "\"" => "\\\"",
           "\010" => "\\b",
................................................................................
             "'"  => $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_callback("/[^\\x{0020}-\\x{007F}]/u", "json_encode___utf8_escape", $var);
         }
         $json = '"' . $var . '"';
      }

      #-- basic types
      elseif (is_bool($var)) {
         $json = $var ? "true" : "false";
................................................................................
         ${'.json_last_error'} = JSON_ERROR_UNSUPPORTED_TYPE;
         return;
      }
      
      #-- done
      return($json);
   }
   function json_encode___utf8_escape($match) {
      return "\\u" . current(unpack("H*", iconv("UTF-8", "UCS-2BE", $match[0])));
   }
}

/**
 * Parses a JSON (JavaScript value expression) string into a PHP variable
 * (array or object).
 *
 * @compat
 *    Behaves similar to PECL version, but is less quiet on errors.
................................................................................
 *
 * @param   $json string   JSON encoded values
 * @param   $assoc bool    pack data into php array/hashes instead of objects
 * @return  mixed          parsed into PHP variable/array/object
 */
if (!function_exists("json_decode")) {

   defined("JSON_OBJECT_AS_ARRAY") or define("JSON_OBJECT_AS_ARRAY", 1);     // undocumented
   defined("JSON_BIGINT_AS_STRING") or define("JSON_BIGINT_AS_STRING", 2);    // 5.4.0
   defined("JSON_PARSE_JAVASCRIPT") or define("JSON_PARSE_JAVASCRIPT", 4);    // unquoted object keys, and single quotes ' strings identical to double quoted, more relaxed parsing

   function json_decode($json, $assoc=FALSE, $limit=512, $options=0, /*emu_args*/$n=0,$state=0,$waitfor=0) {
      global ${'.json_last_error'};
      ${'.json_last_error'} = JSON_ERROR_NONE;

      #-- maximum nesting depth for decoding
      if ($limit < 0) {