|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2002-01-06 09:10 UTC] mfischer@php.net
  [2002-01-27 05:20 UTC] sander@php.net
  [2002-06-22 07:54 UTC] cox@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 18:00:01 2025 UTC | 
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>