PHP 4.0 Bug #10254: xml_set_object() and segmentation fault
| From: | mnino at insight dot com | Date: | Mon, 09 Apr 2001 22:06:25 +0000 |
| Subject: | PHP 4.0 Bug #10254: xml_set_object() and segmentation fault | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-51244@lists.php.net to get a copy of this message | ||
From: mnino@insight.com
Operating system: Redhat 6.2
PHP version: 4.0.4pl1
PHP Bug Type: XML related
Bug description: xml_set_object() and segmentation fault
I am receiving "segmentation fault" when using xml_set_object() and setting handlers in
the constructor. I moved them to the parse() method and the crashes stop. I found the resolution for
a similiar issue in the feedback thread at the end of xml_set_object() documentation just in case
you guys are already aware of this issue : )
Feedback Thread
===============
williams@cse.unl.edu
06-Dec-2000 12:42
If xml_set_object is not called in the constructor of an object, the values that the parser modifies
will be saved. Else, the values do not seem to be saved as stated by "i_sofer" above.
--- Start Example Code ---
class foo {
var xmlparser;
function foo() { \\the constructor
$this->xmlparser=xmlparser_create();
}
function parse() {
xml_set_object($this->xmlparser,&$this);
\\also include data handler
\\and element handlers here
}
}
--- End Example Code ---
My Code
=======
function parse($data) {
$this->parser = xml_parser_create();
xml_set_object($this->parser,&$this);
xml_set_element_handler($this->parser,"tag_open","tag_close");
xml_set_character_data_handler($this->parser,"cdata");
xml_set_processing_instruction_handler($this->parser,"tag_pi");
xml_parse($this->parser,$data);
if (!xml_parse($this->parser, $data, 1)) {
$error = sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->parser)),
xml_get_current_line_number($this->parser));
echo $error;
} // if
xml_parser_free($this->parser);
} // fn
--
Edit Bug report at: http://bugs.php.net/?id=10254&edit=1