From 3c0169f225ba1b5e9675a95bf30a49746566206e Mon Sep 17 00:00:00 2001
From: jrfnl <jrfnl@users.noreply.github.com>
Date: Mon, 22 Jul 2019 05:13:24 +0200
Subject: [PATCH] [External Services_JSON] PHP 7.4 compatibility: fix
deprecated curly brace array access
PHP 7.4 will deprecated array access using curly braces.
Ref: https://wiki.php.net/rfc/deprecate_curly_braces_array_access
---
src/wp-includes/class-json.php | 76 +++++++++++++++++-----------------
1 file changed, 38 insertions(+), 38 deletions(-)
diff --git a/src/wp-includes/class-json.php b/src/wp-includes/class-json.php
index a8c61c92e9..4e512f5c26 100644
a
|
b
|
class Services_JSON |
177 | 177 | return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16'); |
178 | 178 | } |
179 | 179 | |
180 | | $bytes = (ord($utf16{0}) << 8) | ord($utf16{1}); |
| 180 | $bytes = (ord($utf16[0]) << 8) | ord($utf16[1]); |
181 | 181 | |
182 | 182 | switch(true) { |
183 | 183 | case ((0x7F & $bytes) == $bytes): |
… |
… |
class Services_JSON |
230 | 230 | case 2: |
231 | 231 | // return a UTF-16 character from a 2-byte UTF-8 char |
232 | 232 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
233 | | return chr(0x07 & (ord($utf8{0}) >> 2)) |
234 | | . chr((0xC0 & (ord($utf8{0}) << 6)) |
235 | | | (0x3F & ord($utf8{1}))); |
| 233 | return chr(0x07 & (ord($utf8[0]) >> 2)) |
| 234 | . chr((0xC0 & (ord($utf8[0]) << 6)) |
| 235 | | (0x3F & ord($utf8[1]))); |
236 | 236 | |
237 | 237 | case 3: |
238 | 238 | // return a UTF-16 character from a 3-byte UTF-8 char |
239 | 239 | // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
240 | | return chr((0xF0 & (ord($utf8{0}) << 4)) |
241 | | | (0x0F & (ord($utf8{1}) >> 2))) |
242 | | . chr((0xC0 & (ord($utf8{1}) << 6)) |
243 | | | (0x7F & ord($utf8{2}))); |
| 240 | return chr((0xF0 & (ord($utf8[0]) << 4)) |
| 241 | | (0x0F & (ord($utf8[1]) >> 2))) |
| 242 | . chr((0xC0 & (ord($utf8[1]) << 6)) |
| 243 | | (0x7F & ord($utf8[2]))); |
244 | 244 | } |
245 | 245 | |
246 | 246 | // ignoring UTF-32 for now, sorry |
… |
… |
class Services_JSON |
323 | 323 | */ |
324 | 324 | for ($c = 0; $c < $strlen_var; ++$c) { |
325 | 325 | |
326 | | $ord_var_c = ord($var{$c}); |
| 326 | $ord_var_c = ord($var[$c]); |
327 | 327 | |
328 | 328 | switch (true) { |
329 | 329 | case $ord_var_c == 0x08: |
… |
… |
class Services_JSON |
346 | 346 | case $ord_var_c == 0x2F: |
347 | 347 | case $ord_var_c == 0x5C: |
348 | 348 | // double quote, slash, slosh |
349 | | $ascii .= '\\'.$var{$c}; |
| 349 | $ascii .= '\\'.$var[$c]; |
350 | 350 | break; |
351 | 351 | |
352 | 352 | case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)): |
353 | 353 | // characters U-00000000 - U-0000007F (same as ASCII) |
354 | | $ascii .= $var{$c}; |
| 354 | $ascii .= $var[$c]; |
355 | 355 | break; |
356 | 356 | |
357 | 357 | case (($ord_var_c & 0xE0) == 0xC0): |
… |
… |
class Services_JSON |
363 | 363 | break; |
364 | 364 | } |
365 | 365 | |
366 | | $char = pack('C*', $ord_var_c, ord($var{$c + 1})); |
| 366 | $char = pack('C*', $ord_var_c, ord($var[$c + 1])); |
367 | 367 | $c += 1; |
368 | 368 | $utf16 = $this->utf82utf16($char); |
369 | 369 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
… |
… |
class Services_JSON |
378 | 378 | // characters U-00000800 - U-0000FFFF, mask 1110XXXX |
379 | 379 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
380 | 380 | $char = pack('C*', $ord_var_c, |
381 | | @ord($var{$c + 1}), |
382 | | @ord($var{$c + 2})); |
| 381 | @ord($var[$c + 1]), |
| 382 | @ord($var[$c + 2])); |
383 | 383 | $c += 2; |
384 | 384 | $utf16 = $this->utf82utf16($char); |
385 | 385 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
… |
… |
class Services_JSON |
394 | 394 | // characters U-00010000 - U-001FFFFF, mask 11110XXX |
395 | 395 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
396 | 396 | $char = pack('C*', $ord_var_c, |
397 | | ord($var{$c + 1}), |
398 | | ord($var{$c + 2}), |
399 | | ord($var{$c + 3})); |
| 397 | ord($var[$c + 1]), |
| 398 | ord($var[$c + 2]), |
| 399 | ord($var[$c + 3])); |
400 | 400 | $c += 3; |
401 | 401 | $utf16 = $this->utf82utf16($char); |
402 | 402 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
… |
… |
class Services_JSON |
411 | 411 | break; |
412 | 412 | } |
413 | 413 | $char = pack('C*', $ord_var_c, |
414 | | ord($var{$c + 1}), |
415 | | ord($var{$c + 2}), |
416 | | ord($var{$c + 3}), |
417 | | ord($var{$c + 4})); |
| 414 | ord($var[$c + 1]), |
| 415 | ord($var[$c + 2]), |
| 416 | ord($var[$c + 3]), |
| 417 | ord($var[$c + 4])); |
418 | 418 | $c += 4; |
419 | 419 | $utf16 = $this->utf82utf16($char); |
420 | 420 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
… |
… |
class Services_JSON |
429 | 429 | // characters U-04000000 - U-7FFFFFFF, mask 1111110X |
430 | 430 | // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8 |
431 | 431 | $char = pack('C*', $ord_var_c, |
432 | | ord($var{$c + 1}), |
433 | | ord($var{$c + 2}), |
434 | | ord($var{$c + 3}), |
435 | | ord($var{$c + 4}), |
436 | | ord($var{$c + 5})); |
| 432 | ord($var[$c + 1]), |
| 433 | ord($var[$c + 2]), |
| 434 | ord($var[$c + 3]), |
| 435 | ord($var[$c + 4]), |
| 436 | ord($var[$c + 5])); |
437 | 437 | $c += 5; |
438 | 438 | $utf16 = $this->utf82utf16($char); |
439 | 439 | $ascii .= sprintf('\u%04s', bin2hex($utf16)); |
… |
… |
class Services_JSON |
626 | 626 | for ($c = 0; $c < $strlen_chrs; ++$c) { |
627 | 627 | |
628 | 628 | $substr_chrs_c_2 = $this->substr8($chrs, $c, 2); |
629 | | $ord_chrs_c = ord($chrs{$c}); |
| 629 | $ord_chrs_c = ord($chrs[$c]); |
630 | 630 | |
631 | 631 | switch (true) { |
632 | 632 | case $substr_chrs_c_2 == '\b': |
… |
… |
class Services_JSON |
656 | 656 | case $substr_chrs_c_2 == '\\/': |
657 | 657 | if (($delim == '"' && $substr_chrs_c_2 != '\\\'') || |
658 | 658 | ($delim == "'" && $substr_chrs_c_2 != '\\"')) { |
659 | | $utf8 .= $chrs{++$c}; |
| 659 | $utf8 .= $chrs[++$c]; |
660 | 660 | } |
661 | 661 | break; |
662 | 662 | |
… |
… |
class Services_JSON |
669 | 669 | break; |
670 | 670 | |
671 | 671 | case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F): |
672 | | $utf8 .= $chrs{$c}; |
| 672 | $utf8 .= $chrs[$c]; |
673 | 673 | break; |
674 | 674 | |
675 | 675 | case ($ord_chrs_c & 0xE0) == 0xC0: |
… |
… |
class Services_JSON |
716 | 716 | } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) { |
717 | 717 | // array, or object notation |
718 | 718 | |
719 | | if ($str{0} == '[') { |
| 719 | if ($str[0] == '[') { |
720 | 720 | $stk = array(SERVICES_JSON_IN_ARR); |
721 | 721 | $arr = array(); |
722 | 722 | } else { |
… |
… |
class Services_JSON |
755 | 755 | $top = end($stk); |
756 | 756 | $substr_chrs_c_2 = $this->substr8($chrs, $c, 2); |
757 | 757 | |
758 | | if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { |
| 758 | if (($c == $strlen_chrs) || (($chrs[$c] == ',') && ($top['what'] == SERVICES_JSON_SLICE))) { |
759 | 759 | // found a comma that is not inside a string, array, etc., |
760 | 760 | // OR we've reached the end of the character list |
761 | 761 | $slice = $this->substr8($chrs, $top['where'], ($c - $top['where'])); |
… |
… |
class Services_JSON |
796 | 796 | |
797 | 797 | } |
798 | 798 | |
799 | | } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { |
| 799 | } elseif ((($chrs[$c] == '"') || ($chrs[$c] == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) { |
800 | 800 | // found a quote, and we are not inside a string |
801 | | array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c})); |
| 801 | array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs[$c])); |
802 | 802 | //print("Found start of string at {$c}\n"); |
803 | 803 | |
804 | | } elseif (($chrs{$c} == $top['delim']) && |
| 804 | } elseif (($chrs[$c] == $top['delim']) && |
805 | 805 | ($top['what'] == SERVICES_JSON_IN_STR) && |
806 | 806 | (($this->strlen8($this->substr8($chrs, 0, $c)) - $this->strlen8(rtrim($this->substr8($chrs, 0, $c), '\\'))) % 2 != 1)) { |
807 | 807 | // found a quote, we're in a string, and it's not escaped |
… |
… |
class Services_JSON |
810 | 810 | array_pop($stk); |
811 | 811 | //print("Found end of string at {$c}: ".$this->substr8($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n"); |
812 | 812 | |
813 | | } elseif (($chrs{$c} == '[') && |
| 813 | } elseif (($chrs[$c] == '[') && |
814 | 814 | in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
815 | 815 | // found a left-bracket, and we are in an array, object, or slice |
816 | 816 | array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false)); |
817 | 817 | //print("Found start of array at {$c}\n"); |
818 | 818 | |
819 | | } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { |
| 819 | } elseif (($chrs[$c] == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) { |
820 | 820 | // found a right-bracket, and we're in an array |
821 | 821 | array_pop($stk); |
822 | 822 | //print("Found end of array at {$c}: ".$this->substr8($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |
823 | 823 | |
824 | | } elseif (($chrs{$c} == '{') && |
| 824 | } elseif (($chrs[$c] == '{') && |
825 | 825 | in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) { |
826 | 826 | // found a left-brace, and we are in an array, object, or slice |
827 | 827 | array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false)); |
828 | 828 | //print("Found start of object at {$c}\n"); |
829 | 829 | |
830 | | } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { |
| 830 | } elseif (($chrs[$c] == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) { |
831 | 831 | // found a right-brace, and we're in an object |
832 | 832 | array_pop($stk); |
833 | 833 | //print("Found end of object at {$c}: ".$this->substr8($chrs, $top['where'], (1 + $c - $top['where']))."\n"); |