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


Built from https://develop.svn.wordpress.org/trunk@32990


git-svn-id: http://core.svn.wordpress.org/trunk@32961 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Aaron Jorbin 2015-06-28 15:27:24 +00:00
parent a6ebaefb92
commit 1525010f74
17 changed files with 372 additions and 50 deletions

View File

@ -27,14 +27,14 @@
*/
class ftp extends ftp_base {
function ftp($verb=FALSE, $le=FALSE) {
$this->__construct($verb, $le);
}
function __construct($verb=FALSE, $le=FALSE) {
parent::__construct(false, $verb, $le);
}
function ftp($verb=FALSE, $le=FALSE) {
$this->__construct($verb, $le);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->

View File

@ -27,14 +27,14 @@
*/
class ftp extends ftp_base {
function ftp($verb=FALSE, $le=FALSE) {
$this->__construct($verb, $le);
}
function __construct($verb=FALSE, $le=FALSE) {
parent::__construct(true, $verb, $le);
}
function ftp($verb=FALSE, $le=FALSE) {
$this->__construct($verb, $le);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Private functions -->
// <!-- --------------------------------------------------------------------------------------- -->

View File

@ -121,10 +121,6 @@ class ftp_base {
var $AutoAsciiExt;
/* Constructor */
function ftp_base($port_mode=FALSE) {
$this->__construct($port_mode);
}
function __construct($port_mode=FALSE, $verb=FALSE, $le=FALSE) {
$this->LocalEcho=$le;
$this->Verbose=$verb;
@ -157,6 +153,10 @@ class ftp_base {
elseif(strtoupper(substr(PHP_OS, 0, 3)) === 'MAC') $this->OS_local=FTP_OS_Mac;
}
function ftp_base($port_mode=FALSE) {
$this->__construct($port_mode);
}
// <!-- --------------------------------------------------------------------------------------- -->
// <!-- Public functions -->
// <!-- --------------------------------------------------------------------------------------- -->

View File

@ -212,7 +212,7 @@
// Note that no real action is taken, if the archive does not exist it is not
// created. Use create() for that.
// --------------------------------------------------------------------------------
function PclZip($p_zipname)
function __construct($p_zipname)
{
// ----- Tests the zlib
@ -229,6 +229,10 @@
// ----- Return
return;
}
public function PclZip($p_zipname) {
self::__construct($p_zipname);
}
// --------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

View File

@ -470,7 +470,7 @@ class WP_User_Search {
var $paging_text;
/**
* PHP4 Constructor - Sets up the object properties.
* PHP5 Constructor - Sets up the object properties.
*
* @since 2.1.0
*
@ -479,7 +479,7 @@ class WP_User_Search {
* @param string $role Role name.
* @return WP_User_Search
*/
function WP_User_Search ($search_term = '', $page = '', $role = '') {
function __construct( $search_term = '', $page = '', $role = '' ) {
_deprecated_function( __FUNCTION__, '3.1', 'WP_User_Query' );
$this->search_term = wp_unslash( $search_term );
@ -492,6 +492,20 @@ class WP_User_Search {
$this->do_paging();
}
/**
* PHP4 Constructor - Sets up the object properties.
*
* @since 2.1.0
*
* @param string $search_term Search terms string.
* @param int $page Optional. Page ID.
* @param string $role Role name.
* @return WP_User_Search
*/
public function WP_User_Search( $search_term = '', $page = '', $role = '' ) {
self::__construct( $search_term, $page, $role );
}
/**
* {@internal Missing Short Description}}
*

View File

@ -33,7 +33,7 @@ class Text_Diff {
* Normally an array of two arrays, each
* containing the lines from a file.
*/
function Text_Diff($engine, $params)
function __construct( $engine, $params )
{
// Backward compatibility workaround.
if (!is_string($engine)) {
@ -55,6 +55,13 @@ class Text_Diff {
$this->_edits = call_user_func_array(array($diff_engine, 'diff'), $params);
}
/**
* PHP4 constructor.
*/
public function Text_Diff( $engine, $params ) {
self::__construct( $engine, $params );
}
/**
* Returns the array of differences.
*/
@ -304,7 +311,7 @@ class Text_MappedDiff extends Text_Diff {
* @param array $mapped_to_lines This array should have the same number
* of elements as $to_lines.
*/
function Text_MappedDiff($from_lines, $to_lines,
function __construct($from_lines, $to_lines,
$mapped_from_lines, $mapped_to_lines)
{
assert(count($from_lines) == count($mapped_from_lines));
@ -328,6 +335,15 @@ class Text_MappedDiff extends Text_Diff {
}
}
/**
* PHP4 constructor.
*/
public function Text_MappedDiff( $from_lines, $to_lines,
$mapped_from_lines, $mapped_to_lines ) {
self::__construct( $from_lines, $to_lines,
$mapped_from_lines, $mapped_to_lines );
}
}
/**
@ -366,7 +382,10 @@ class Text_Diff_Op {
*/
class Text_Diff_Op_copy extends Text_Diff_Op {
function Text_Diff_Op_copy($orig, $final = false)
/**
* PHP5 constructor.
*/
function __construct( $orig, $final = false )
{
if (!is_array($final)) {
$final = $orig;
@ -375,6 +394,13 @@ class Text_Diff_Op_copy extends Text_Diff_Op {
$this->final = $final;
}
/**
* PHP4 constructor.
*/
public function Text_Diff_Op_copy( $orig, $final = false ) {
self::__construct( $orig, $final );
}
function &reverse()
{
$reverse = new Text_Diff_Op_copy($this->final, $this->orig);
@ -391,12 +417,22 @@ class Text_Diff_Op_copy extends Text_Diff_Op {
*/
class Text_Diff_Op_delete extends Text_Diff_Op {
function Text_Diff_Op_delete($lines)
/**
* PHP5 constructor.
*/
function __construct( $lines )
{
$this->orig = $lines;
$this->final = false;
}
/**
* PHP4 constructor.
*/
public function Text_Diff_Op_delete( $lines ) {
self::__construct( $lines );
}
function &reverse()
{
$reverse = new Text_Diff_Op_add($this->orig);
@ -413,12 +449,22 @@ class Text_Diff_Op_delete extends Text_Diff_Op {
*/
class Text_Diff_Op_add extends Text_Diff_Op {
function Text_Diff_Op_add($lines)
/**
* PHP5 constructor.
*/
function __construct( $lines )
{
$this->final = $lines;
$this->orig = false;
}
/**
* PHP4 constructor.
*/
public function Text_Diff_Op_add( $lines ) {
self::__construct( $lines );
}
function &reverse()
{
$reverse = new Text_Diff_Op_delete($this->final);
@ -435,12 +481,22 @@ class Text_Diff_Op_add extends Text_Diff_Op {
*/
class Text_Diff_Op_change extends Text_Diff_Op {
function Text_Diff_Op_change($orig, $final)
/**
* PHP5 constructor.
*/
function __construct( $orig, $final )
{
$this->orig = $orig;
$this->final = $final;
}
/**
* PHP4 constructor.
*/
public function Text_Diff_Op_change( $orig, $final ) {
self::__construct( $orig, $final );
}
function &reverse()
{
$reverse = new Text_Diff_Op_change($this->final, $this->orig);

View File

@ -33,7 +33,7 @@ class Text_Diff_Renderer {
/**
* Constructor.
*/
function Text_Diff_Renderer($params = array())
function __construct( $params = array() )
{
foreach ($params as $param => $value) {
$v = '_' . $param;
@ -43,6 +43,13 @@ class Text_Diff_Renderer {
}
}
/**
* PHP4 constructor.
*/
public function Text_Diff_Renderer( $params = array() ) {
self::__construct( $params );
}
/**
* Get any renderer parameters.
*

View File

@ -87,7 +87,10 @@ class AtomParser {
var $feed;
var $current;
function AtomParser() {
/**
* PHP5 constructor.
*/
function __construct() {
$this->feed = new AtomFeed();
$this->current = null;
@ -95,6 +98,13 @@ class AtomParser {
$this->map_xmlns_func = create_function('$p,$n', '$xd = "xmlns"; if(strlen($n[0])>0) $xd .= ":{$n[0]}"; return "{$xd}=\"{$n[1]}\"";');
}
/**
* PHP4 constructor.
*/
public function AtomParser() {
self::__construct();
}
function _p($msg) {
if($this->debug) {
print str_repeat(" ", $this->depth * $this->indent) . $msg ."\n";

View File

@ -49,7 +49,10 @@ class IXR_Value {
var $data;
var $type;
function IXR_Value($data, $type = false)
/**
* PHP5 constructor.
*/
function __construct( $data, $type = false )
{
$this->data = $data;
if (!$type) {
@ -69,6 +72,13 @@ class IXR_Value {
}
}
/**
* PHP4 constructor.
*/
public function IXR_Value( $data, $type = false ) {
self::__construct( $data, $type );
}
function calculateType()
{
if ($this->data === true || $this->data === false) {
@ -194,11 +204,21 @@ class IXR_Message
// The XML parser
var $_parser;
function IXR_Message($message)
/**
* PHP5 constructor.
*/
function __construct( $message )
{
$this->message =& $message;
}
/**
* PHP4 constructor.
*/
public function IXR_Message( $message ) {
self::__construct( $message );
}
function parse()
{
// first remove the XML declaration
@ -386,7 +406,10 @@ class IXR_Server
var $message;
var $capabilities;
function IXR_Server($callbacks = false, $data = false, $wait = false)
/**
* PHP5 constructor.
*/
function __construct( $callbacks = false, $data = false, $wait = false )
{
$this->setCapabilities();
if ($callbacks) {
@ -398,6 +421,13 @@ class IXR_Server
}
}
/**
* PHP4 constructor.
*/
public function IXR_Server( $callbacks = false, $data = false, $wait = false ) {
self::__construct( $callbacks, $data, $wait );
}
function serve($data = false)
{
if (!$data) {
@ -600,7 +630,10 @@ class IXR_Request
var $args;
var $xml;
function IXR_Request($method, $args)
/**
* PHP5 constructor.
*/
function __construct($method, $args)
{
$this->method = $method;
$this->args = $args;
@ -620,6 +653,13 @@ EOD;
$this->xml .= '</params></methodCall>';
}
/**
* PHP4 constructor.
*/
public function IXR_Request( $method, $args ) {
self::__construct( $method, $args );
}
function getLength()
{
return strlen($this->xml);
@ -653,7 +693,10 @@ class IXR_Client
// Storage place for an error message
var $error = false;
function IXR_Client($server, $path = false, $port = 80, $timeout = 15)
/**
* PHP5 constructor.
*/
function __construct( $server, $path = false, $port = 80, $timeout = 15 )
{
if (!$path) {
// Assume we have been given a URL instead
@ -679,6 +722,13 @@ class IXR_Client
$this->timeout = $timeout;
}
/**
* PHP4 constructor.
*/
public function IXR_Client( $server, $path = false, $port = 80, $timeout = 15 ) {
self::__construct( $server, $path, $port, $timeout );
}
function query()
{
$args = func_get_args();
@ -798,12 +848,22 @@ class IXR_Error
var $code;
var $message;
function IXR_Error($code, $message)
/**
* PHP5 constructor.
*/
function __construct( $code, $message )
{
$this->code = $code;
$this->message = htmlspecialchars($message);
}
/**
* PHP4 constructor.
*/
public function IXR_Error( $code, $message ) {
self::__construct( $code, $message );
}
function getXml()
{
$xml = <<<EOD
@ -844,7 +904,10 @@ class IXR_Date {
var $second;
var $timezone;
function IXR_Date($time)
/**
* PHP5 constructor.
*/
function __construct( $time )
{
// $time can be a PHP timestamp or an ISO one
if (is_numeric($time)) {
@ -854,6 +917,13 @@ class IXR_Date {
}
}
/**
* PHP4 constructor.
*/
public function IXR_Date( $time ) {
self::__construct( $time );
}
function parseTimestamp($timestamp)
{
$this->year = date('Y', $timestamp);
@ -902,11 +972,21 @@ class IXR_Base64
{
var $data;
function IXR_Base64($data)
/**
* PHP5 constructor.
*/
function __construct( $data )
{
$this->data = $data;
}
/**
* PHP4 constructor.
*/
public function IXR_Base64( $data ) {
self::__construct( $data );
}
function getXml()
{
return '<base64>'.base64_encode($this->data).'</base64>';
@ -924,7 +1004,10 @@ class IXR_IntrospectionServer extends IXR_Server
var $signatures;
var $help;
function IXR_IntrospectionServer()
/**
* PHP5 constructor.
*/
function __construct()
{
$this->setCallbacks();
$this->setCapabilities();
@ -958,6 +1041,13 @@ class IXR_IntrospectionServer extends IXR_Server
);
}
/**
* PHP4 constructor.
*/
public function IXR_IntrospectionServer() {
self::__construct();
}
function addCallback($method, $callback, $args, $help)
{
$this->callbacks[$method] = $callback;
@ -1086,12 +1176,22 @@ class IXR_ClientMulticall extends IXR_Client
{
var $calls = array();
function IXR_ClientMulticall($server, $path = false, $port = 80)
/**
* PHP5 constructor.
*/
function __construct( $server, $path = false, $port = 80 )
{
parent::IXR_Client($server, $path, $port);
$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)';
}
/**
* PHP4 constructor.
*/
public function IXR_ClientMulticall( $server, $path = false, $port = 80 ) {
self::__construct( $server, $path, $port );
}
function addCall()
{
$args = func_get_args();

View File

@ -140,13 +140,20 @@ class Services_JSON
* strings or numbers, if you return an object, make sure it does
* not have a toJSON method, otherwise an error will occur.
*/
function Services_JSON($use = 0)
function __construct( $use = 0 )
{
$this->use = $use;
$this->_mb_strlen = function_exists('mb_strlen');
$this->_mb_convert_encoding = function_exists('mb_convert_encoding');
$this->_mb_substr = function_exists('mb_substr');
}
/**
* PHP4 constructor.
*/
public function Services_JSON( $use = 0 ) {
self::__construct( $use );
}
// private - cache the mbstring lookup results..
var $_mb_strlen = false;
var $_mb_substr = false;
@ -910,11 +917,17 @@ if (class_exists('PEAR_Error')) {
class Services_JSON_Error extends PEAR_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
function __construct($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
{
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
}
public function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null) {
self::__construct($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null);
}
}
} else {
@ -924,11 +937,22 @@ if (class_exists('PEAR_Error')) {
*/
class Services_JSON_Error
{
function Services_JSON_Error($message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null)
/**
* PHP5 constructor.
*/
function __construct( $message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null )
{
}
/**
* PHP4 constructor.
*/
public function Services_JSON_Error( $message = 'unknown error', $code = null,
$mode = null, $options = null, $userinfo = null ) {
self::__construct( $message, $code, $mode, $options, $userinfo );
}
}
}

View File

@ -39,7 +39,10 @@ class PasswordHash {
var $portable_hashes;
var $random_state;
function PasswordHash($iteration_count_log2, $portable_hashes)
/**
* PHP5 constructor.
*/
function __construct( $iteration_count_log2, $portable_hashes )
{
$this->itoa64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
@ -52,6 +55,13 @@ class PasswordHash {
$this->random_state = microtime() . uniqid(rand(), TRUE); // removed getmypid() for compatibility reasons
}
/**
* PHP4 constructor.
*/
public function PasswordHash( $iteration_count_log2, $portable_hashes ) {
self::__construct( $iteration_count_log2, $portable_hashes );
}
function get_random_bytes($count)
{
$output = '';

View File

@ -44,7 +44,10 @@ class POP3 {
// This must be set to true
// manually
function POP3 ( $server = '', $timeout = '' ) {
/**
* PHP5 constructor.
*/
function __construct ( $server = '', $timeout = '' ) {
settype($this->BUFFER,"integer");
if( !empty($server) ) {
// Do not allow programs to alter MAILSERVER
@ -62,6 +65,13 @@ class POP3 {
return true;
}
/**
* PHP4 constructor.
*/
public function POP3( $server = '', $timeout = '' ) {
self::__construct( $server, $timeout );
}
function update_timer () {
if (!ini_get('safe_mode'))
set_time_limit($this->TIMEOUT);

View File

@ -40,7 +40,7 @@ class Translation_Entry {
* - references (array) -- places in the code this strings is used, in relative_to_root_path/file.php:linenum form
* - flags (array) -- flags like php-format
*/
function Translation_Entry($args=array()) {
function __construct( $args = array() ) {
// if no singular -- empty object
if (!isset($args['singular'])) {
return;
@ -55,6 +55,13 @@ class Translation_Entry {
if (!is_array($this->flags)) $this->flags = array();
}
/**
* PHP4 constructor.
*/
public function Translation_Entry( $args = array() ) {
self::__construct( $args );
}
/**
* Generates a unique key for this entry
*

View File

@ -14,11 +14,21 @@ class POMO_Reader {
var $endian = 'little';
var $_post = '';
function POMO_Reader() {
/**
* PHP5 constructor.
*/
function __construct() {
$this->is_overloaded = ((ini_get("mbstring.func_overload") & 2) != 0) && function_exists('mb_substr');
$this->_pos = 0;
}
/**
* PHP4 constructor.
*/
public function POMO_Reader() {
self::__construct();
}
/**
* Sets the endianness of the file.
*
@ -130,11 +140,18 @@ class POMO_FileReader extends POMO_Reader {
/**
* @param string $filename
*/
function POMO_FileReader($filename) {
function __construct( $filename ) {
parent::POMO_Reader();
$this->_f = fopen($filename, 'rb');
}
/**
* PHP4 constructor.
*/
public function POMO_FileReader( $filename ) {
self::__construct( $filename );
}
/**
* @param int $bytes
*/
@ -196,12 +213,22 @@ class POMO_StringReader extends POMO_Reader {
var $_str = '';
function POMO_StringReader($str = '') {
/**
* PHP5 constructor.
*/
function __construct( $str = '' ) {
parent::POMO_Reader();
$this->_str = $str;
$this->_pos = 0;
}
/**
* PHP4 constructor.
*/
public function POMO_StringReader( $str = '' ) {
self::__construct( $str );
}
/**
* @param string $bytes
* @return string
@ -245,13 +272,23 @@ if ( !class_exists( 'POMO_CachedFileReader' ) ):
* Reads the contents of the file in the beginning.
*/
class POMO_CachedFileReader extends POMO_StringReader {
function POMO_CachedFileReader($filename) {
/**
* PHP5 constructor.
*/
function __construct( $filename ) {
parent::POMO_StringReader();
$this->_str = file_get_contents($filename);
if (false === $this->_str)
return false;
$this->_pos = 0;
}
/**
* PHP4 constructor.
*/
public function POMO_CachedFileReader( $filename ) {
self::__construct( $filename );
}
}
endif;
@ -260,8 +297,19 @@ if ( !class_exists( 'POMO_CachedIntFileReader' ) ):
* Reads the contents of the file in the beginning.
*/
class POMO_CachedIntFileReader extends POMO_CachedFileReader {
function POMO_CachedIntFileReader($filename) {
/**
* PHP5 constructor.
*/
public function __construct( $filename ) {
parent::POMO_CachedFileReader($filename);
}
/**
* PHP4 constructor.
*/
function POMO_CachedIntFileReader( $filename ) {
self::__construct( $filename );
}
}
endif;
endif;

View File

@ -55,7 +55,10 @@ class MagpieRSS {
var $_CONTENT_CONSTRUCTS = array('content', 'summary', 'info', 'title', 'tagline', 'copyright');
function MagpieRSS ($source) {
/**
* PHP5 constructor.
*/
function __construct( $source ) {
# if PHP xml isn't compiled in, die
#
@ -97,6 +100,13 @@ class MagpieRSS {
$this->normalize();
}
/**
* PHP4 constructor.
*/
public function MagpieRSS( $source ) {
self::__construct( $source );
}
function feed_start_element($p, $element, &$attrs) {
$el = $element = strtolower($element);
$attrs = array_change_key_case($attrs, CASE_LOWER);
@ -709,7 +719,10 @@ class RSSCache {
var $MAX_AGE = 43200; // when are files stale, default twelve hours
var $ERROR = ''; // accumulate error messages
function RSSCache ($base='', $age='') {
/**
* PHP5 constructor.
*/
function __construct( $base = '', $age = '' ) {
$this->BASE_CACHE = WP_CONTENT_DIR . '/cache';
if ( $base ) {
$this->BASE_CACHE = $base;
@ -720,6 +733,13 @@ class RSSCache {
}
/**
* PHP4 constructor.
*/
public function RSSCache( $base = '', $age = '' ) {
self::__construct( $base, $age );
}
/*=======================================================================*\
Function: set
Purpose: add an item to the cache, keyed on url

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-alpha-32989';
$wp_version = '4.3-alpha-32990';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -173,6 +173,7 @@ class WP_Widget {
* @param array $control_options
*/
public function WP_Widget( $id_base, $name, $widget_options = array(), $control_options = array() ) {
_deprecated_constructor( 'WP_Widget', '4.3.0' );
WP_Widget::__construct( $id_base, $name, $widget_options, $control_options );
}
@ -563,10 +564,21 @@ class WP_Widget {
class WP_Widget_Factory {
public $widgets = array();
public function WP_Widget_Factory() {
/**
* PHP5 constructor.
*/
public function __construct() {
add_action( 'widgets_init', array( $this, '_register_widgets' ), 100 );
}
/**
* PHP4 constructor.
*/
public function WP_Widget_Factory() {
_deprecated_constructor( 'WP_Widget_Factory', '4.2.0' );
self::__construct();
}
/**
* Register a widget subclass.
*