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



git-svn-id: https://develop.svn.wordpress.org/trunk@32990 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Aaron Jorbin
2015-06-28 15:26:41 +00:00
parent 6c8944b6ea
commit 4a60647ab7
19 changed files with 415 additions and 54 deletions
+62 -6
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);