From 26e22ab837dcabe137a0912fcd2f96d0c35f48c8 Mon Sep 17 00:00:00 2001 From: Christopher Smith <chris@jalakai.co.uk> Date: Fri, 15 May 2015 19:03:34 +0200 Subject: [PATCH] Changes for PHP 7 Compatibility - replace PHP4 style class constructor function names (based on class name) with php 5 __construct() Also remove some '&' reference operators used with objects And add some object type hints --- _test/tests/inc/parser/lexer.test.php | 4 +- inc/IXR_Library.php | 20 ++++---- inc/events.php | 4 +- inc/form.php | 2 +- inc/parser/handler.php | 48 +++++++++++--------- inc/parser/lexer.php | 6 +-- inc/parser/parser.php | 20 ++++---- lib/plugins/config/settings/config.class.php | 4 +- lib/plugins/config/settings/extra.class.php | 2 +- lib/plugins/popularity/action.php | 2 +- lib/plugins/popularity/admin.php | 2 +- lib/plugins/popularity/helper.php | 2 +- lib/plugins/usermanager/admin.php | 2 +- 13 files changed, 62 insertions(+), 56 deletions(-) diff --git a/_test/tests/inc/parser/lexer.test.php b/_test/tests/inc/parser/lexer.test.php index d0965a13e..c50665928 100644 --- a/_test/tests/inc/parser/lexer.test.php +++ b/_test/tests/inc/parser/lexer.test.php @@ -146,7 +146,7 @@ class TestOfLexerStateStack extends DokuWikiTest { } class TestParser { - function TestParser() { + function __construct() { } function accept() { } @@ -364,7 +364,7 @@ class TestOfLexerHandlers extends DokuWikiTest { class TestParserByteIndex { - function TestParserByteIndex() {} + function __construct() {} function ignore() {} diff --git a/inc/IXR_Library.php b/inc/IXR_Library.php index 839298680..301a8d9e1 100644 --- a/inc/IXR_Library.php +++ b/inc/IXR_Library.php @@ -52,7 +52,7 @@ class IXR_Value { * @param mixed $data * @param bool $type */ - function IXR_Value($data, $type = false) { + function __construct($data, $type = false) { $this->data = $data; if(!$type) { $type = $this->calculateType(); @@ -201,7 +201,7 @@ class IXR_Message { /** * @param string $message */ - function IXR_Message($message) { + function __construct($message) { $this->message =& $message; } @@ -388,7 +388,7 @@ class IXR_Server { * @param bool $data * @param bool $wait */ - function IXR_Server($callbacks = false, $data = false, $wait = false) { + function __construct($callbacks = false, $data = false, $wait = false) { $this->setCapabilities(); if($callbacks) { $this->callbacks = $callbacks; @@ -621,7 +621,7 @@ class IXR_Request { * @param string $method * @param array $args */ - function IXR_Request($method, $args) { + function __construct($method, $args) { $this->method = $method; $this->args = $args; $this->xml = <<<EOD @@ -684,7 +684,7 @@ class IXR_Client extends DokuHTTPClient { * @param int $port * @param int $timeout */ - function IXR_Client($server, $path = false, $port = 80, $timeout = 15) { + function __construct($server, $path = false, $port = 80, $timeout = 15) { parent::__construct(); if(!$path) { // Assume we have been given a URL instead @@ -779,7 +779,7 @@ class IXR_Error { * @param int $code * @param string $message */ - function IXR_Error($code, $message) { + function __construct($code, $message) { $this->code = $code; $this->message = htmlspecialchars($message); } @@ -829,7 +829,7 @@ class IXR_Date { /** * @param int|string $time */ - function IXR_Date($time) { + function __construct($time) { // $time can be a PHP timestamp or an ISO one if(is_numeric($time)) { $this->parseTimestamp($time); @@ -899,7 +899,7 @@ class IXR_Base64 { /** * @param string $data */ - function IXR_Base64($data) { + function __construct($data) { $this->data = $data; } @@ -923,7 +923,7 @@ class IXR_IntrospectionServer extends IXR_Server { /** @var string[] */ var $help; - function IXR_IntrospectionServer() { + function __construct() { $this->setCallbacks(); $this->setCapabilities(); $this->capabilities['introspection'] = array( @@ -1106,7 +1106,7 @@ class IXR_ClientMulticall extends IXR_Client { * @param string|bool $path * @param int $port */ - function IXR_ClientMulticall($server, $path = false, $port = 80) { + function __construct($server, $path = false, $port = 80) { parent::IXR_Client($server, $path, $port); //$this->useragent = 'The Incutio XML-RPC PHP Library (multicall client)'; } diff --git a/inc/events.php b/inc/events.php index 256fb561e..35d55d0e3 100644 --- a/inc/events.php +++ b/inc/events.php @@ -31,7 +31,7 @@ class Doku_Event { * @param string $name * @param mixed $data */ - function Doku_Event($name, &$data) { + function __construct($name, &$data) { $this->name = $name; $this->data =& $data; @@ -153,7 +153,7 @@ class Doku_Event_Handler { * constructor, loads all action plugins and calls their register() method giving them * an opportunity to register any hooks they require */ - function Doku_Event_Handler() { + function __construct() { // load action plugins /** @var DokuWiki_Action_Plugin $plugin */ diff --git a/inc/form.php b/inc/form.php index 00eea9b3a..748983281 100644 --- a/inc/form.php +++ b/inc/form.php @@ -55,7 +55,7 @@ class Doku_Form { * * @author Tom N Harris <tnharris@whoopdedo.org> */ - function Doku_Form($params, $action=false, $method=false, $enctype=false) { + function __construct($params, $action=false, $method=false, $enctype=false) { if(!is_array($params)) { $this->params = array('id' => $params); if ($action !== false) $this->params['action'] = $action; diff --git a/inc/parser/handler.php b/inc/parser/handler.php index b8e2de82a..815ac39c5 100644 --- a/inc/parser/handler.php +++ b/inc/parser/handler.php @@ -17,7 +17,7 @@ class Doku_Handler { var $rewriteBlocks = true; - function Doku_Handler() { + function __construct() { $this->CallWriter = new Doku_Handler_CallWriter($this); } @@ -295,7 +295,7 @@ class Doku_Handler { switch ( $state ) { case DOKU_LEXER_ENTER: $ReWriter = new Doku_Handler_Preformatted($this->CallWriter); - $this->CallWriter = & $ReWriter; + $this->CallWriter = $ReWriter; $this->_addCall('preformatted_start',array(), $pos); break; case DOKU_LEXER_EXIT: @@ -715,15 +715,21 @@ function Doku_Handler_Parse_Media($match) { } //------------------------------------------------------------------------ -class Doku_Handler_CallWriter { +interface Doku_Handler_CallWriter_Interface { + public function writeCall($call); + public function writeCalls($calls); + public function finalise(); +} + +class Doku_Handler_CallWriter implements Doku_Handler_CallWriter_Interface { var $Handler; /** * @param Doku_Handler $Handler */ - function Doku_Handler_CallWriter(& $Handler) { - $this->Handler = & $Handler; + function __construct(Doku_Handler $Handler) { + $this->Handler = $Handler; } function writeCall($call) { @@ -748,7 +754,7 @@ class Doku_Handler_CallWriter { * * @author Chris Smith <chris@jalakai.co.uk> */ -class Doku_Handler_Nest { +class Doku_Handler_Nest implements Doku_Handler_CallWriter_Interface { var $CallWriter; var $calls = array(); @@ -762,8 +768,8 @@ class Doku_Handler_Nest { * @param string $close closing instruction name, this is required to properly terminate the * syntax mode if the document ends without a closing pattern */ - function Doku_Handler_Nest(& $CallWriter, $close="nest_close") { - $this->CallWriter = & $CallWriter; + function __construct(Doku_Handler_CallWriter_Interface $CallWriter, $close="nest_close") { + $this->CallWriter = $CallWriter; $this->closingInstruction = $close; } @@ -808,7 +814,7 @@ class Doku_Handler_Nest { } } -class Doku_Handler_List { +class Doku_Handler_List implements Doku_Handler_CallWriter_Interface { var $CallWriter; @@ -818,8 +824,8 @@ class Doku_Handler_List { const NODE = 1; - function Doku_Handler_List(& $CallWriter) { - $this->CallWriter = & $CallWriter; + function __construct(Doku_Handler_CallWriter_Interface $CallWriter) { + $this->CallWriter = $CallWriter; } function writeCall($call) { @@ -1018,7 +1024,7 @@ class Doku_Handler_List { } //------------------------------------------------------------------------ -class Doku_Handler_Preformatted { +class Doku_Handler_Preformatted implements Doku_Handler_CallWriter_Interface { var $CallWriter; @@ -1028,8 +1034,8 @@ class Doku_Handler_Preformatted { - function Doku_Handler_Preformatted(& $CallWriter) { - $this->CallWriter = & $CallWriter; + function __construct(Doku_Handler_CallWriter_Interface $CallWriter) { + $this->CallWriter = $CallWriter; } function writeCall($call) { @@ -1078,7 +1084,7 @@ class Doku_Handler_Preformatted { } //------------------------------------------------------------------------ -class Doku_Handler_Quote { +class Doku_Handler_Quote implements Doku_Handler_CallWriter_Interface { var $CallWriter; @@ -1086,8 +1092,8 @@ class Doku_Handler_Quote { var $quoteCalls = array(); - function Doku_Handler_Quote(& $CallWriter) { - $this->CallWriter = & $CallWriter; + function __construct(Doku_Handler_CallWriter_Interface $CallWriter) { + $this->CallWriter = $CallWriter; } function writeCall($call) { @@ -1170,7 +1176,7 @@ class Doku_Handler_Quote { } //------------------------------------------------------------------------ -class Doku_Handler_Table { +class Doku_Handler_Table implements Doku_Handler_CallWriter_Interface { var $CallWriter; @@ -1185,8 +1191,8 @@ class Doku_Handler_Table { var $currentRow = array('tableheader' => 0, 'tablecell' => 0); var $countTableHeadRows = 0; - function Doku_Handler_Table(& $CallWriter) { - $this->CallWriter = & $CallWriter; + function __construct(Doku_Handler_CallWriter_Interface $CallWriter) { + $this->CallWriter = $CallWriter; } function writeCall($call) { @@ -1551,7 +1557,7 @@ class Doku_Handler_Block { * * @author Andreas Gohr <andi@splitbrain.org> */ - function Doku_Handler_Block(){ + function __construct(){ global $DOKU_PLUGINS; //check if syntax plugins were loaded if(empty($DOKU_PLUGINS['syntax'])) return; diff --git a/inc/parser/lexer.php b/inc/parser/lexer.php index b46a5f505..5afcc520a 100644 --- a/inc/parser/lexer.php +++ b/inc/parser/lexer.php @@ -46,7 +46,7 @@ class Doku_LexerParallelRegex { * for insensitive. * @access public */ - function Doku_LexerParallelRegex($case) { + function __construct($case) { $this->_case = $case; $this->_patterns = array(); $this->_labels = array(); @@ -232,7 +232,7 @@ class Doku_LexerStateStack { * @param string $start Starting state name. * @access public */ - function Doku_LexerStateStack($start) { + function __construct($start) { $this->_stack = array($start); } @@ -296,7 +296,7 @@ class Doku_Lexer { * @param boolean $case True for case sensitive. * @access public */ - function Doku_Lexer(&$parser, $start = "accept", $case = false) { + function __construct(&$parser, $start = "accept", $case = false) { $this->_case = $case; /** @var Doku_LexerParallelRegex[] _regexes */ $this->_regexes = array(); diff --git a/inc/parser/parser.php b/inc/parser/parser.php index 5f86cf5c4..65510071e 100644 --- a/inc/parser/parser.php +++ b/inc/parser/parser.php @@ -226,7 +226,7 @@ class Doku_Parser_Mode_Plugin extends DokuWiki_Plugin implements Doku_Parser_Mod //------------------------------------------------------------------- class Doku_Parser_Mode_base extends Doku_Parser_Mode { - function Doku_Parser_Mode_base() { + function __construct() { global $PARSER_MODES; $this->allowedModes = array_merge ( @@ -248,7 +248,7 @@ class Doku_Parser_Mode_base extends Doku_Parser_Mode { //------------------------------------------------------------------- class Doku_Parser_Mode_footnote extends Doku_Parser_Mode { - function Doku_Parser_Mode_footnote() { + function __construct() { global $PARSER_MODES; $this->allowedModes = array_merge ( @@ -416,7 +416,7 @@ class Doku_Parser_Mode_formatting extends Doku_Parser_Mode { /** * @param string $type */ - function Doku_Parser_Mode_formatting($type) { + function __construct($type) { global $PARSER_MODES; if ( !array_key_exists($type, $this->formatting) ) { @@ -470,7 +470,7 @@ class Doku_Parser_Mode_formatting extends Doku_Parser_Mode { //------------------------------------------------------------------- class Doku_Parser_Mode_listblock extends Doku_Parser_Mode { - function Doku_Parser_Mode_listblock() { + function __construct() { global $PARSER_MODES; $this->allowedModes = array_merge ( @@ -504,7 +504,7 @@ class Doku_Parser_Mode_listblock extends Doku_Parser_Mode { //------------------------------------------------------------------- class Doku_Parser_Mode_table extends Doku_Parser_Mode { - function Doku_Parser_Mode_table() { + function __construct() { global $PARSER_MODES; $this->allowedModes = array_merge ( @@ -648,7 +648,7 @@ class Doku_Parser_Mode_file extends Doku_Parser_Mode { //------------------------------------------------------------------- class Doku_Parser_Mode_quote extends Doku_Parser_Mode { - function Doku_Parser_Mode_quote() { + function __construct() { global $PARSER_MODES; $this->allowedModes = array_merge ( @@ -682,7 +682,7 @@ class Doku_Parser_Mode_acronym extends Doku_Parser_Mode { var $acronyms = array(); var $pattern = ''; - function Doku_Parser_Mode_acronym($acronyms) { + function __construct($acronyms) { usort($acronyms,array($this,'_compare')); $this->acronyms = $acronyms; } @@ -729,7 +729,7 @@ class Doku_Parser_Mode_smiley extends Doku_Parser_Mode { var $smileys = array(); var $pattern = ''; - function Doku_Parser_Mode_smiley($smileys) { + function __construct($smileys) { $this->smileys = $smileys; } @@ -762,7 +762,7 @@ class Doku_Parser_Mode_wordblock extends Doku_Parser_Mode { var $badwords = array(); var $pattern = ''; - function Doku_Parser_Mode_wordblock($badwords) { + function __construct($badwords) { $this->badwords = $badwords; } @@ -797,7 +797,7 @@ class Doku_Parser_Mode_entity extends Doku_Parser_Mode { var $entities = array(); var $pattern = ''; - function Doku_Parser_Mode_entity($entities) { + function __construct($entities) { $this->entities = $entities; } diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php index 316cc2c59..f2d43bff6 100644 --- a/lib/plugins/config/settings/config.class.php +++ b/lib/plugins/config/settings/config.class.php @@ -37,7 +37,7 @@ if (!class_exists('configuration')) { * * @param string $datafile path to config metadata file */ - public function configuration($datafile) { + public function __construct($datafile) { global $conf, $config_cascade; if (!file_exists($datafile)) { @@ -434,7 +434,7 @@ if (!class_exists('setting')) { * @param string $key * @param array|null $params array with metadata of setting */ - public function setting($key, $params=null) { + public function __construct($key, $params=null) { $this->_key = $key; if (is_array($params)) { diff --git a/lib/plugins/config/settings/extra.class.php b/lib/plugins/config/settings/extra.class.php index fd3a90e28..c6a3f9dae 100644 --- a/lib/plugins/config/settings/extra.class.php +++ b/lib/plugins/config/settings/extra.class.php @@ -20,7 +20,7 @@ if (!class_exists('setting_sepchar')) { for ($i=0;$i<strlen($str);$i++) $this->_choices[] = $str{$i}; // call foundation class constructor - $this->setting($key,$param); + parent::__construct($key,$param); } } } diff --git a/lib/plugins/popularity/action.php b/lib/plugins/popularity/action.php index 9e2e78d11..d5ec0f5c5 100644 --- a/lib/plugins/popularity/action.php +++ b/lib/plugins/popularity/action.php @@ -15,7 +15,7 @@ class action_plugin_popularity extends Dokuwiki_Action_Plugin { */ var $helper; - function action_plugin_popularity(){ + function __construct(){ $this->helper = $this->loadHelper('popularity', false); } diff --git a/lib/plugins/popularity/admin.php b/lib/plugins/popularity/admin.php index ab569b8b4..a2c3c6c8b 100644 --- a/lib/plugins/popularity/admin.php +++ b/lib/plugins/popularity/admin.php @@ -20,7 +20,7 @@ class admin_plugin_popularity extends DokuWiki_Admin_Plugin { var $helper; var $sentStatus = null; - function admin_plugin_popularity(){ + function __construct(){ $this->helper = $this->loadHelper('popularity', false); } diff --git a/lib/plugins/popularity/helper.php b/lib/plugins/popularity/helper.php index 8673fb5af..e99f6a60c 100644 --- a/lib/plugins/popularity/helper.php +++ b/lib/plugins/popularity/helper.php @@ -30,7 +30,7 @@ class helper_plugin_popularity extends Dokuwiki_Plugin { var $popularityLastSubmitFile; - function helper_plugin_popularity(){ + function __construct(){ global $conf; $this->autosubmitFile = $conf['cachedir'].'/autosubmit.txt'; $this->autosubmitErrorFile = $conf['cachedir'].'/autosubmitError.txt'; diff --git a/lib/plugins/usermanager/admin.php b/lib/plugins/usermanager/admin.php index 9cb9b0c40..0d92e5cc1 100644 --- a/lib/plugins/usermanager/admin.php +++ b/lib/plugins/usermanager/admin.php @@ -36,7 +36,7 @@ class admin_plugin_usermanager extends DokuWiki_Admin_Plugin { /** * Constructor */ - public function admin_plugin_usermanager(){ + public function __construct(){ /** @var DokuWiki_Auth_Plugin $auth */ global $auth; -- GitLab