php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17560 dump_mem with format mangles doc for subsequent requests
Submitted: 2002-06-02 00:29 UTC Modified: 2002-06-04 10:37 UTC
From: jhpellerin at attbi dot com Assigned:
Status: Closed Package: DOM XML related
PHP Version: 4.2.1 OS: Linux (redhat 7.2) + Apache 1.3.
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jhpellerin at attbi dot com
New email:
PHP Version: OS:

 

 [2002-06-02 00:29 UTC] jhpellerin at attbi dot com
Calling $doc->dump_mem or $doc->dump_file with format set to true seems to corrupt the internal representation of the XML document, removing all writespace-only text nodes, which alters the structure of the document. It doesn't affect the document object in the same request, but all subsequent requests that access an identical XML doc -- even on a different page -- will see the altered structure instead of the structure actually present in the original doc.

Workaround: set format to false

Config:  './configure' '--with-apxs=/opt/apache/bin/apxs' '--with-dom' '-with-dom-xslt' '--with-dom-exslt' '--prefix=/opt' '--with-zlib'

Demo script:

<?php

$xml = "<?xml version=\"1.0\"?>
<motel>
<roaches>
<roach state=\"alive\"/>
<roach state=\"dead\"/>
<roach state=\"dead\"/>
</roaches>
</motel>";

$doc = domxml_open_mem($xml);
echo "First listing:<br>\n";
list_roaches($doc);

/*
  Calling dump mem with format set to true
  alters the in-memory copy the xml file, even
  across reloads of the page!

  With the whitespace stripped, the structure
  of the document changes.
 */
$foo = $doc->dump_mem(true);

echo "After doc->dump_mem called:<br>\n";
list_roaches($doc);

echo "Now, reload to see error<br>\n";

function list_roaches ($doc)
{
  $root         = $doc->document_element(); 
  $first_child  = $root->first_child();
  $roaches_el   = $first_child->next_sibling();
 
  if ($roaches_el) {
    $roaches_list = $roaches_el->get_elements_by_tagname("roach");
    for ($i = 0; $i < count($roaches_list); $i++) {
      echo " Roach $i is " . $roaches_list[$i]->get_attribute("state")
	. "<br>\n";
    }
  } else {
    echo "No sibling of first child found!<br><xmp>\n";
    echo $doc->dump_mem();
    echo "</xmp>\n";
  }
}

?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-04 10:37 UTC] jtate@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.

Applied patch by Rob Richards.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 23 06:01:35 2024 UTC