ID: 24002
Updated by: [EMAIL PROTECTED]
Reported By: derek at hostopia dot com
-Status: Open
+Status: Verified
Bug Type: XML related
Operating System: Linux
-PHP Version: 4.3.2
+PHP Version: 4.3.3-dev
New Comment:
Works fine with PHP 4.2.3, breaks with 4.3.1, 4.3.2, 4.3.3-dev.
Previous Comments:
------------------------------------------------------------------------
[2003-06-04 13:43:11] derek at hostopia dot com
Here as requested is an example which works fine under 4.2.2, and
causes an endless loop in 4.3.2:
<!-- BEGIN XML FILE: shapes.xml -->
<SCREEN>
<INFO>This will render a random surprise shape</INFO>
<RANDOM shapes="SQUARE TRIANGLE CIRCLE"/>
</SCREEN>
<!-- END XML FILE -->
### CUT HERE ###
<!-- BEGIN PHP FILE: shapes.php -->
<?php
$file = "shapes.xml";
function startElement($parser, $name, $attribs) {
switch ($name)
{
case "RANDOM":
$list = explode(" ", $attribs["SHAPES"]);
$num = count($list);
$rnd = rand(1, $num) - 1;
$xml = "<" . $list[$rnd] . "/>";
if ( !xml_parse($parser, $xml) )
{
print xml_error_string(xml_get_error_code($parser));
}
break;
case "SQUARE":
print "\n ################\n";
print " ################\n";
print " ################\n";
print " ################\n";
print " ################\n";
print " ################\n";
print " ################\n";
print " ################\n";
break;
case "TRIANGLE":
print "\n ## \n";
print " #### \n";
print " ###### \n";
print " ######## \n";
print " ########## \n";
print " ############ \n";
print " ############## \n";
print " ################\n";
break;
case "CIRCLE":
print "\n ######## \n";
print " ############ \n";
print " ############## \n";
print " ############## \n";
print " ############## \n";
print " ############## \n";
print " ############ \n";
print " ######## \n";
break;
}
}
function endElement($parser, $name) {
}
function characterData($parser, $data) {
print "<b>$data</b>";
}
function defaultHandler($parser, $data) {
if (substr($data, 0, 1) == "&" && substr($data, -1, 1) == ";") {
printf('<font color="#aa00aa">%s</font>',
htmlspecialchars($data));
} else {
printf('<font size="-1">%s</font>',
htmlspecialchars($data));
}
}
function new_xml_parser($file) {
global $parser_file;
$xml_parser = xml_parser_create();
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
xml_set_element_handler($xml_parser, "startElement",
"endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_default_handler($xml_parser, "defaultHandler");
if (!($fp = @fopen($file, "r"))) {
return false;
}
if (!is_array($parser_file)) {
settype($parser_file, "array");
}
$parser_file[$xml_parser] = $file;
return array($xml_parser, $fp);
}
if (!(list($xml_parser, $fp) = new_xml_parser($file))) {
die("could not open XML input");
}
print "<pre>";
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d\n",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
print "</pre>";
print "parse complete\n";
xml_parser_free($xml_parser);
?>
<!-- END PHP FILE -->
------------------------------------------------------------------------
[2003-06-03 22:16:21] [EMAIL PROTECTED]
Please provide a short but complete example script.
------------------------------------------------------------------------
[2003-06-03 16:14:29] derek at hostopia dot com
PHP versions up to and including 4.2.2 supported calling xml_parse from
within an xml element/data handler, but when tested with version 4.3.2,
this functionality produces unexpected results.
Sometimes the error 'xml processing instruction not at start of
external entity' occurs, but most of the time the xml parser will get
stuck in an endless loop.
A rather massive PHP application makes use of this feature, and we
currently do not have a work-around.
Basically we need XML elements to be able to give dynamic XML content
to the XML parser.
This was working fine up until now, and is quite important.
Is there a "better way" to accomplish this if in fact this use of
xml_parse is unorthodox?
For example, this XML-based code:
<SCREEN>
<INFO>This will render a random surprise shape</INFO>
<RANDOM shapes="SQUARE, TRIANGLE, CIRCLE"/>
</SCREEN>
Where the element handler for "RANDOM" will give a random XML element
to the parser... i.e. <SQUARE width="5" height="5"/>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=24002&edit=1