Bug #7133 Updated: xml_set_object() should not copy the object

From: Date: Sat, 22 Jun 2002 11:54:10 +0000
Subject: Bug #7133 Updated: xml_set_object() should not copy the object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-11775@lists.php.net to get a copy of this message
ID: 7133 Updated by: cox@php.net Reported By: mookid@sigent.ru -Status: No Feedback +Status: Bogus Bug Type: XML related Operating System: irrelevant PHP Version: 4.0.2 New Comment: It's a must to create the object by reference: $parser = &new MyParser(); Tomas V.V.Cox Previous Comments: ------------------------------------------------------------------------ [2002-01-27 05:20:02] sander@php.net No feedback. ------------------------------------------------------------------------ [2002-01-06 09:10:20] mfischer@php.net Does this still apply to 4.1.1? ------------------------------------------------------------------------ [2000-10-11 07:49:48] mookid@sigent.ru Playing with XML_Parser, I was discouraged by the fact that xml_set_object() actually copies an object even if it's been passed by reference. This is a PITA when you want tag handlers to store parsed data into object's properties and use these properties afterwards. You have to assign references to these propeties in order to access values out of handler context. Here's an example script: <?php require_once('XML/Parser.php'); $global_accum = ''; class MyParser extends XML_Parser { var $accum; var $ref_accum; function MyParser() { global $global_accum; $this->ref_accum = &$global_accum; $this->XML_Parser('ISO-8859-1'); } function startHandler($parser, $tag, $attrs) { $this->accum .= "<$tag>"; $this->ref_accum .= "<$tag>"; } function endHandler($parser, $tag) { $this->accum .= "</$tag>"; $this->ref_accum .= "</$tag>"; } } header('Content-Type: text/plain'); $parser = new MyParser(); $data = <<<EOD <?xml version="1.0"?> <!DOCTYPE foo SYSTEM "/dtd/foo.dtd"> <foo> <bar/> </foo> EOD; $err = $parser->parseString($data, TRUE); if (PEAR::isError($err)) { die($err->getMessage()); } echo "accum: ", $parser->accum, "\n"; echo "ref_accum: ", $parser->ref_accum, "\n"; ?> This produces: accum: ref_accum: <FOO><BAR></BAR></FOO> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=7133&edit=1

« previous php.bugs (#11775) next »