Make WordPress Core

Changeset 46205


Ignore:
Timestamp:
09/20/2019 07:52:38 PM (7 years ago)
Author:
desrosj
Message:

Code Modernization: Deprecate the Services_JSON and Services_JSON_Error classes.

The PHP native JSON extension has been bundled and compiled with PHP by default since version 5.2.0. Because the minimum version of PHP required by WordPress is now 5.6.20 (see #46594 and [45058]), JSON extension related polyfills and backwards compatibility code can now be removed.

Since there are still some plugins and themes that utilize the Services_JSON class, these classes will remain for the time being, but including the wp-includes/class-json.php file and creating Services_JSON instances will now throw deprecated notices.

See #47699.
Props jrf, Clorith, pento.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-json.php

    r45730 r46205  
    11<?php
     2_deprecated_file( basename( __FILE__ ), '5.3.0', null, 'The PHP native JSON extension is now a requirement.' );
     3
    24if ( ! class_exists( 'Services_JSON' ) ) :
    35/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
    … …  
    143145    function __construct( $use = 0 )
    144146    {
     147        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     148
    145149        $this->use = $use;
    146150        $this->_mb_strlen            = function_exists('mb_strlen');
    … …  
    153157         */
    154158        public function Services_JSON( $use = 0 ) {
     159                _deprecated_constructor( 'Services_JSON', '5.3.0', get_class( $this ) );
    155160                self::__construct( $use );
    156161        }
    … …  
    173178    function utf162utf8($utf16)
    174179    {
     180        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     181
    175182        // oh please oh please oh please oh please oh please
    176183        if($this->_mb_convert_encoding) {
    … …  
    217224    function utf82utf16($utf8)
    218225    {
     226        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     227
    219228        // oh please oh please oh please oh please oh please
    220229        if($this->_mb_convert_encoding) {
    … …  
    261270    function encode($var)
    262271    {
     272        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     273
    263274        header('Content-type: application/json');
    264275        return $this->encodeUnsafe($var);
    … …  
    277288    function encodeUnsafe($var)
    278289    {
     290        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     291
    279292        // see bug #16908 - regarding numeric locale printing
    280293        $lc = setlocale(LC_NUMERIC, 0);
    … …  
    298311    function _encode($var)
    299312    {
    300          
     313        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     314
    301315        switch (gettype($var)) {
    302316            case 'boolean':
    … …  
    540554    function name_value($name, $value)
    541555    {
     556        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     557
    542558        $encoded_value = $this->_encode($value);
    543559
    … …  
    559575    function reduce_string($str)
    560576    {
     577        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     578
    561579        $str = preg_replace(array(
    562580
    … …  
    590608    function decode($str)
    591609    {
     610        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     611
    592612        $str = $this->reduce_string($str);
    593613
    … …  
    775795                               
    776796                               if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:/Uis', $slice, $parts)) {
    777                                       // "name":value pair
     797                                    // "name":value pair
    778798                                    $key = $this->decode($parts[1]);
    779799                                    $val = $this->decode(trim(substr($slice, strlen($parts[0])), ", \t\n\r\0\x0B"));
    … …  
    871891    function isError($data, $code = null)
    872892    {
     893        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     894
    873895        if (class_exists('pear')) {
    874896            return PEAR::isError($data, $code);
    … …  
    888910    function strlen8( $str )
    889911    {
     912        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     913
    890914        if ( $this->_mb_strlen ) {
    891915            return mb_strlen( $str, "8bit" );
    … …  
    903927    function substr8( $string, $start, $length=false )
    904928    {
     929        _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     930
    905931        if ( $length === false ) {
    906932            $length = $this->strlen8( $string ) - $start;
    … …  
    921947                                     $mode = null, $options = null, $userinfo = null)
    922948        {
     949            _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
     950
    923951            parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
    924952        }
    925953
    926         public function Services_JSON_Error($message = 'unknown error', $code = null,
     954                public function Services_JSON_Error($message = 'unknown error', $code = null,
    927955                                     $mode = null, $options = null, $userinfo = null) {
    928                 self::__construct($message = 'unknown error', $code = null,
    929                                      $mode = null, $options = null, $userinfo = null);
    930         }
     956                        _deprecated_constructor( 'Services_JSON_Error', '5.3.0', get_class( $this ) );
     957                        self::__construct($message, $code, $mode, $options, $userinfo);
     958                }
    931959    }
    932960
    … …  
    944972                                     $mode = null, $options = null, $userinfo = null )
    945973        {
    946 
     974            _deprecated_function( __METHOD__, '5.3.0', 'The PHP native JSON extension' );
    947975        }
    948976
    … …  
    952980                public function Services_JSON_Error( $message = 'unknown error', $code = null,
    953981                                             $mode = null, $options = null, $userinfo = null ) {
     982                        _deprecated_constructor( 'Services_JSON_Error', '5.3.0', get_class( $this ) );
    954983                        self::__construct( $message, $code, $mode, $options, $userinfo );
    955984                }
    956985    }
    957    
     986
    958987}
    959988
  • trunk/tests/phpunit/tests/compat.php

    r45607 r46205  
    180180        }
    181181
     182        /**
     183         * @expectedException PHPUnit_Framework_Error_Notice
     184         */
    182185        function test_json_encode_decode() {
    183186                require_once( ABSPATH . WPINC . '/class-json.php' );
Note: See TracChangeset for help on using the changeset viewer.