php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23531 Can't reset internal treenode to correctly reread xml document
Submitted: 2003-05-07 13:02 UTC Modified: 2003-05-07 16:49 UTC
From: bharris at spro dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 4.3.2RC2 OS: Red Hat 8.0
Private report: No CVE-ID: None
 [2003-05-07 13:02 UTC] bharris at spro dot net
--SCRIPT--
$xmlstr = '<?xml version="1.0"?><configuration><datasources><subtree name="Test"><apply-template name="test.xml.com"/></subtree></datasources></configuration>';
$dom = domxml_open_mem($xmlstr);
$root = $dom->document_element();
$element = 0;
transversenodes($root, 'first');
$dom->free();
$dom = domxml_open_mem($xmlstr);
$root = $dom->document_element();
$element = 0;
transversenodes($root, 'second');
nice_r($_SESSION);

function transversenodes (&$node, $string) {
    global $element;
    if ($node->has_child_nodes()) {
        $child = $node->child_nodes();
        for ($i = 0; $i < count($child); $i++) {
            if ($child[$i]->node_type() == XML_ELEMENT_NODE) {
                if ($child[$i]->tagname == 'apply-template') {
                    $_SESSION[$string][$element] = $child[$i];
                    $element++;
                    break;
                }
                if ($child[$i]->tagname == 'subtree') {
                    $_SESSION[$string][$element] = $child[$i];
                    $element++;
                }
                transversenodes($child[$i], $string);
            }
        }
    }
}

function nice_r (&$variable) {
    echo "<pre>\n";
    print_r($variable);
    echo "</pre>\n";
}
--MODULES--
'./configure' '--host=i386-redhat-linux' '--build=i386-redhat-linux' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--prefix=/usr' '--with-config-file-path=/etc' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-curl' '--with-dom=/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd' '--enable-gd-native-ttf' '--with-ttf' '--with-gdbm' '--with-gettext' '--with-ncurses' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-pspell' '--with-xml' '--with-expat-dir=/usr' '--with-zlib' '--with-layout=GNU' '--enable-bcmath' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos=/usr/kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--with-pgsql=shared' '--with-snmp=shared,/usr' '--with-snmp=shared' '--enable-ucd-snmp-hack' '--with-unixODBC=shared' '--enable-memory-limit' '--enable-bcmath' '--enable-shmop' '--enable-versioning' '--enable-calendar' '--enable-dbx' '--enable-dio' '--enable-mcal' '--with-apxs2=/usr/sbin/apxs'
--COMMENTS--
I appologize for the length of the test script but I couldn't trim it any more to show my point
My problem is that I can't reset the internal namespace for DOMXML documents unless I load a new page (i.e. can't reset the dom space within a single script).  I need to have access to functions that will do whatever is done between page loads because that successfully resets the internal treenode pointer.  I need to be able to load a document into an internal treenode, modify it, write it to file then display a graphical hyperlinked representation of the modified treenode on the same "page".  Without being able to reset the internal treenode my serialized objects don't point at the correct object on the next page and I get an error.  Reclicking the same hyperlink at this point works because ending the script the first time resets the internal treenode correctly.  I thought $dom->free() would work but it appears it's not, if you run my script you'll see that the object id's are different for the second dom object even though it's the same document, just reloaded.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-07 15:29 UTC] chregu@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The internal node pointer (I assume you mean the 0 and 
1 properties) were never meant to be used in PHP 
Userland. Don't rely on them... 

That these pointers are exposed to the outside looks is 
a misconception in the domxml extension.

chregu
 [2003-05-07 15:42 UTC] bharris at spro dot net
Did I report the bug incorrectly?  I read both those documents prior to reporting the bug.

I'm not relying directly on the 0 and 1 pointers, I was only using those to expose what I think is still a bug.  What I am doing is reading a document, targeting nodes in that document, serializing those nodes via the SESSION and then on a subsequent page reaccessing those nodes (after reading the same document).  This works fine unless I have to reload the same document in the same script. Unfortunately not being able to completely free (i.e. reset) the internal document skews the objects and it errors on the next page.  Is DOMELEMENT/NODE OBJECT serialization not supported?  Should I be using Xpath to target/retarget nodes?
 [2003-05-07 16:30 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You can't serialize these objects. Use Xpath to query the tree. Also, once you call free() what you are seeing in your session are just emtpy wrappers as the entire tree is freed. If you try to use them with domxml functionality, you will see that the underlying data is gone.

You are better off using the domxml functions rather than properties from the objects
 [2003-05-07 16:49 UTC] bharris at spro dot net
Ok, I'll go the XPath route...disappointing since it was working rather good for simple stuff.  You're right the underlying objects were empty once free was called...however, if on the net page you read the same document and transversed it identically, the serialized objects were valid, you could use them without having to query again.  Neat trick, eh?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 13:01:30 2024 UTC