Skip to content

Commit 4036bad

Browse files
committed
make XML_Parser run on PHP7
1 parent 0ebb53a commit 4036bad

File tree

10 files changed

+36
-68
lines changed

10 files changed

+36
-68
lines changed

XML/Parser.php

Lines changed: 16 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -191,26 +191,6 @@ class XML_Parser extends PEAR
191191
*/
192192
var $_validEncodings = array('ISO-8859-1', 'UTF-8', 'US-ASCII');
193193

194-
// }}}
195-
// {{{ php4 constructor
196-
197-
/**
198-
* Creates an XML parser.
199-
*
200-
* This is needed for PHP4 compatibility, it will
201-
* call the constructor, when a new instance is created.
202-
*
203-
* @param string $srcenc source charset encoding, use NULL (default) to use
204-
* whatever the document specifies
205-
* @param string $mode how this parser object should work, "event" for
206-
* startelement/endelement-type events, "func"
207-
* to have it call functions named after elements
208-
* @param string $tgtenc a valid target encoding
209-
*/
210-
function XML_Parser($srcenc = null, $mode = 'event', $tgtenc = null)
211-
{
212-
XML_Parser::__construct($srcenc, $mode, $tgtenc);
213-
}
214194
// }}}
215195
// {{{ php5 constructor
216196

@@ -226,7 +206,7 @@ function XML_Parser($srcenc = null, $mode = 'event', $tgtenc = null)
226206
*/
227207
function __construct($srcenc = null, $mode = 'event', $tgtenc = null)
228208
{
229-
$this->PEAR('XML_Parser_Error');
209+
parent::__construct('XML_Parser_Error');
230210

231211
$this->mode = $mode;
232212
$this->srcenc = $srcenc;
@@ -279,9 +259,9 @@ function setMode($mode)
279259
* @access public
280260
* @since v1.2.0beta3
281261
*/
282-
function setHandlerObj(&$obj)
262+
function setHandlerObj($obj)
283263
{
284-
$this->_handlerObj = &$obj;
264+
$this->_handlerObj = $obj;
285265
return true;
286266
}
287267

@@ -298,14 +278,14 @@ function _initHandlers()
298278
}
299279

300280
if (!is_object($this->_handlerObj)) {
301-
$this->_handlerObj = &$this;
281+
$this->_handlerObj = $this;
302282
}
303283
switch ($this->mode) {
304284

305285
case 'func':
306286
xml_set_object($this->parser, $this->_handlerObj);
307-
xml_set_element_handler($this->parser,
308-
array(&$this, 'funcStartHandler'), array(&$this, 'funcEndHandler'));
287+
xml_set_element_handler($this->parser,
288+
array($this, 'funcStartHandler'), array($this, 'funcEndHandler'));
309289
break;
310290

311291
case 'event':
@@ -513,15 +493,15 @@ function parse()
513493

514494
while ($data = fread($this->fp, 4096)) {
515495
if (!$this->_parseString($data, feof($this->fp))) {
516-
$error = &$this->raiseError();
496+
$error = $this->raiseError();
517497
$this->free();
518498
return $error;
519499
}
520500
}
521501
} else {
522502
// otherwise, $this->fp must be a string
523503
if (!$this->_parseString($this->fp, true)) {
524-
$error = &$this->raiseError();
504+
$error = $this->raiseError();
525505
$this->free();
526506
return $error;
527507
}
@@ -569,7 +549,7 @@ function parseString($data, $eof = false)
569549
}
570550

571551
if (!$this->_parseString($data, $eof)) {
572-
$error = &$this->raiseError();
552+
$error = $this->raiseError();
573553
$this->free();
574554
return $error;
575555
}
@@ -610,10 +590,10 @@ function free()
610590
*
611591
* @return XML_Parser_Error reference to the error object
612592
**/
613-
function &raiseError($msg = null, $ecode = 0)
593+
function raiseError($msg = null, $ecode = 0)
614594
{
615595
$msg = !is_null($msg) ? $msg : $this->parser;
616-
$err = &new XML_Parser_Error($msg, $ecode);
596+
$err = new XML_Parser_Error($msg, $ecode);
617597
return parent::raiseError($err);
618598
}
619599

@@ -634,9 +614,9 @@ function funcStartHandler($xp, $elem, $attribs)
634614
$func = 'xmltag_' . $elem;
635615
$func = str_replace(array('.', '-', ':'), '_', $func);
636616
if (method_exists($this->_handlerObj, $func)) {
637-
call_user_func(array(&$this->_handlerObj, $func), $xp, $elem, $attribs);
617+
call_user_func(array($this->_handlerObj, $func), $xp, $elem, $attribs);
638618
} elseif (method_exists($this->_handlerObj, 'xmltag')) {
639-
call_user_func(array(&$this->_handlerObj, 'xmltag'),
619+
call_user_func(array($this->_handlerObj, 'xmltag'),
640620
$xp, $elem, $attribs);
641621
}
642622
}
@@ -657,9 +637,9 @@ function funcEndHandler($xp, $elem)
657637
$func = 'xmltag_' . $elem . '_';
658638
$func = str_replace(array('.', '-', ':'), '_', $func);
659639
if (method_exists($this->_handlerObj, $func)) {
660-
call_user_func(array(&$this->_handlerObj, $func), $xp, $elem);
640+
call_user_func(array($this->_handlerObj, $func), $xp, $elem);
661641
} elseif (method_exists($this->_handlerObj, 'xmltag_')) {
662-
call_user_func(array(&$this->_handlerObj, 'xmltag_'), $xp, $elem);
642+
call_user_func(array($this->_handlerObj, 'xmltag_'), $xp, $elem);
663643
}
664644
}
665645

@@ -761,7 +741,7 @@ function XML_Parser_Error($msgorparser = 'unknown error', $code = 0, $mode = PEA
761741
xml_get_current_line_number($msgorparser),
762742
xml_get_current_column_number($msgorparser));
763743
}
764-
$this->PEAR_Error($msgorparser, $code, $mode, $level);
744+
parent::__construct($msgorparser, $code, $mode, $level);
765745
}
766746
// }}}
767747
}

XML/Parser/Simple.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@
7272
* {
7373
* $this->XML_Parser_Simple();
7474
* }
75-
*
75+
*
7676
* function handleElement($name, $attribs, $data)
7777
* {
7878
* printf('handle %s<br>', $name);
7979
* }
8080
* }
81-
*
82-
* $p = &new myParser();
83-
*
81+
*
82+
* $p = new myParser();
83+
*
8484
* $result = $p->setInputFile('myDoc.xml');
8585
* $result = $p->parse();
8686
* </code>
@@ -145,9 +145,9 @@ class XML_Parser_Simple extends XML_Parser
145145
* named after elements (handleElement_$name())
146146
* @param string $tgtenc a valid target encoding
147147
*/
148-
function XML_Parser_Simple($srcenc = null, $mode = 'event', $tgtenc = null)
148+
function __construct($srcenc = null, $mode = 'event', $tgtenc = null)
149149
{
150-
$this->XML_Parser($srcenc, $mode, $tgtenc);
150+
parent::__construct($srcenc, $mode, $tgtenc);
151151
}
152152

153153
/**
@@ -159,7 +159,7 @@ function XML_Parser_Simple($srcenc = null, $mode = 'event', $tgtenc = null)
159159
function _initHandlers()
160160
{
161161
if (!is_object($this->_handlerObj)) {
162-
$this->_handlerObj = &$this;
162+
$this->_handlerObj = $this;
163163
}
164164

165165
if ($this->mode != 'func' && $this->mode != 'event') {
@@ -168,10 +168,10 @@ function _initHandlers()
168168
}
169169
xml_set_object($this->parser, $this->_handlerObj);
170170

171-
xml_set_element_handler($this->parser, array(&$this, 'startHandler'),
172-
array(&$this, 'endHandler'));
173-
xml_set_character_data_handler($this->parser, array(&$this, 'cdataHandler'));
174-
171+
xml_set_element_handler($this->parser, array($this, 'startHandler'),
172+
array($this, 'endHandler'));
173+
xml_set_character_data_handler($this->parser, array($this, 'cdataHandler'));
174+
175175
/**
176176
* set additional handlers for character data, entities, etc.
177177
*/
@@ -256,7 +256,7 @@ function endHandler($xp, $elem)
256256
$func = str_replace('.', '_', $func);
257257
}
258258
if (method_exists($this->_handlerObj, $func)) {
259-
call_user_func(array(&$this->_handlerObj, $func),
259+
call_user_func(array($this->_handlerObj, $func),
260260
$el['name'], $el['attribs'], $data);
261261
}
262262
break;

tests/001.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ XML Parser: parse simple string
1313
require_once "XML/Parser.php";
1414

1515
class __TestParser1 extends XML_Parser {
16-
function __TestParser1() {
17-
$this->XML_Parser();
18-
}
19-
function startHandler($xp, $element, $attribs) {
16+
function startHandler($xp, $element, &$attribs) {
2017
print "<$element";
2118
reset($attribs);
2219
while (list($key, $val) = each($attribs)) {

tests/002.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ XML Parser: parse from file
1313
require_once "XML/Parser.php";
1414

1515
class __TestParser2 extends XML_Parser {
16-
function __TestParser2() {
17-
$this->XML_Parser();
18-
}
19-
function startHandler($xp, $element, $attribs) {
16+
function startHandler($xp, $element, &$attribs) {
2017
print "<$element";
2118
reset($attribs);
2219
while (list($key, $val) = each($attribs)) {

tests/003.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ XML Parser: parse from file resource
1313
require_once "XML/Parser.php";
1414

1515
class __TestParser3 extends XML_Parser {
16-
function __TestParser3() {
17-
$this->XML_Parser();
18-
}
19-
function startHandler($xp, $element, $attribs) {
16+
function startHandler($xp, $element, &$attribs) {
2017
print "<$element";
2118
reset($attribs);
2219
while (list($key, $val) = each($attribs)) {

tests/005.phpt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ require_once 'XML/Parser.php';
3232
class TestEncodings1 extends XML_Parser {
3333
var $output = '';
3434

35-
function TestEncodings1($to, $mode, $from) {
36-
$this->XML_Parser($from, $mode, $to);
37-
}
3835
function startHandler($xp, $elem, $attribs) {
3936
$this->output .= "<$elem>";
4037
}
@@ -69,7 +66,7 @@ foreach ($input as $srcenc => $string) {
6966
continue;
7067
}
7168
print "Testing $srcenc -> $tgtenc: ";
72-
$p =& new TestEncodings1($tgtenc, 'event', $srcenc);
69+
$p = new TestEncodings1($tgtenc, 'event', $srcenc);
7370
$e = $p->test($input[$srcenc]);
7471
if (PEAR::isError($e)) {
7572
printf("OOPS: %s\n", $e->getMessage());

tests/bug-9328.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ error_reporting($originalErrorReporting);
2727
require_once 'XML/RSS.php';
2828

2929
$url = 'www.someverybogusurl.thisisnotatld';
30-
$rss =& new XML_RSS($url);
30+
$rss = new XML_RSS($url);
3131

3232
$error = $rss->parse();
3333
echo $error->getMessage() . PHP_EOL;

tests/bug-9328b.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ error_reporting($originalErrorReporting);
2929
require_once 'XML/RSS.php';
3030

3131
$url = 'www.someverybogusurl.thisisnotatld';
32-
$rss =& new XML_RSS($url);
32+
$rss = new XML_RSS($url);
3333

3434
$error = $rss->parse();
3535
echo $error->getMessage() . PHP_EOL;

tests/bug-9328c.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ error_reporting($originalErrorReporting);
2929
require_once 'XML/RSS.php';
3030

3131
$url = 'www.someverybogusurl.thisisnotatld';
32-
$rss =& new XML_RSS($url);
32+
$rss = new XML_RSS($url);
3333

3434
$error = $rss->parse();
3535
echo $error->getMessage() . PHP_EOL;

tests/bug-9328d.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ error_reporting($originalErrorReporting);
2727
require_once 'XML/RSS.php';
2828

2929
$url = 'www.someverybogusurl.thisisnotatld';
30-
$rss =& new XML_RSS($url);
30+
$rss = new XML_RSS($url);
3131

3232
$error = $rss->parse();
3333
echo $error->getMessage() . PHP_EOL;

0 commit comments

Comments
 (0)