|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7133 xml_set_object() should not copy the object
Submitted: 2000-10-11 07:49 UTC Modified: 2002-06-22 07:54 UTC
From: mookid at sigent dot ru Assigned:
Status: Not a bug Package: XML related
PHP Version: 4.0.2 OS: irrelevant
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mookid at sigent dot ru
New email:
PHP Version: OS:


 [2000-10-11 07:49 UTC] mookid at sigent dot 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:



$global_accum = '';

class MyParser extends XML_Parser {

	var $accum;
	var $ref_accum;

	function MyParser()
		global $global_accum;
		$this->ref_accum = &$global_accum;

	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">

$err = $parser->parseString($data, TRUE);

if (PEAR::isError($err)) {

echo "accum: ", $parser->accum, "\n";
echo "ref_accum: ", $parser->ref_accum, "\n";


This produces:

ref_accum: <FOO><BAR></BAR></FOO>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-06 09:10 UTC]
Does this still apply to 4.1.1?
 [2002-01-27 05:20 UTC]
No feedback.
 [2002-06-22 07:54 UTC]
It's a must to create the object by reference:

$parser = &new MyParser();

Tomas V.V.Cox
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Nov 29 05:05:53 2022 UTC