Make WordPress Core


Ignore:
Timestamp:
06/28/2015 03:26:41 PM (9 years ago)
Author:
jorbin
Message:

Deprecate php4 style constructors

PHP7 is deprecating PHP4 style constructors, so we need to modify our code to have _construct methods that fire before the named PHP4 style constructors. The PHP4 style constructors will call the PHP5 style constructor in case it is being called directly (usually via parent::METHOD).

This modifies external libraries to add PHP5 style constructors, but doesn't add a notice for when they are used. In WordPress core code, PHP4 style constructors are being given a call to _deprecated_constructor. To the PHP4 style constructor I say "I know that I can't take no more | It ain't no lie | I wanna see you out that door | Baby, bye, bye, bye..."

Upstream: https://wiki.php.net/rfc/remove_php4_constructors

Props jdgrimes, netweb, jorbin
See #31982

File:
1 edited

Legend:

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

    r24587 r32990  
    141141    *                                   not have a toJSON method, otherwise an error will occur.
    142142    */
    143     function Services_JSON($use = 0)
     143    function __construct( $use = 0 )
    144144    {
    145145        $this->use = $use;
     
    148148        $this->_mb_substr            = function_exists('mb_substr');
    149149    }
     150
     151    /**
     152     * PHP4 constructor.
     153     */
     154    public function Services_JSON( $use = 0 ) {
     155        self::__construct( $use );
     156    }
    150157    // private - cache the mbstring lookup results..
    151158    var $_mb_strlen = false;
     
    911918    class Services_JSON_Error extends PEAR_Error
    912919    {
    913         function Services_JSON_Error($message = 'unknown error', $code = null,
     920        function __construct($message = 'unknown error', $code = null,
    914921                                     $mode = null, $options = null, $userinfo = null)
    915922        {
    916923            parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
    917924        }
     925
     926    public function Services_JSON_Error($message = 'unknown error', $code = null,
     927                                     $mode = null, $options = null, $userinfo = null) {
     928        self::__construct($message = 'unknown error', $code = null,
     929                                     $mode = null, $options = null, $userinfo = null);
     930    }
    918931    }
    919932
     
    925938    class Services_JSON_Error
    926939    {
    927         function Services_JSON_Error($message = 'unknown error', $code = null,
    928                                      $mode = null, $options = null, $userinfo = null)
     940        /**
     941         * PHP5 constructor.
     942         */
     943        function __construct( $message = 'unknown error', $code = null,
     944                                     $mode = null, $options = null, $userinfo = null )
    929945        {
    930946
    931947        }
     948
     949        /**
     950         * PHP4 constructor.
     951         */
     952        public function Services_JSON_Error( $message = 'unknown error', $code = null,
     953                                         $mode = null, $options = null, $userinfo = null ) {
     954            self::__construct( $message, $code, $mode, $options, $userinfo );
     955        }
    932956    }
    933957   
Note: See TracChangeset for help on using the changeset viewer.