php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29386 unexpected result - $dom->saveXML()
Submitted: 2004-07-26 12:06 UTC Modified: 2004-08-11 01:00 UTC
Votes:5
Avg. Score:4.6 ± 0.8
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:1 (33.3%)
From: bugz at nagash dot org Assigned:
Status: No Feedback Package: DOM XML related
PHP Version: 5.0.0 OS: windows
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bugz at nagash dot org
New email:
PHP Version: OS:

 

 [2004-07-26 12:06 UTC] bugz at nagash dot org
Description:
------------
result is unexpected

Reproduce code:
---------------
$doc = new DOMDocument("1.0");
$root = $doc->createElement("HTML");
$root = $doc->appendChild($root);
$head = $doc->createElement("HEAD");
$head = $root->appendChild($head);
$title = $doc->createElement("TITLE");
$title = $head->appendChild($title);
$text = $doc->createTextNode("This is the title");
$text = $title->appendChild($text);
echo $doc->saveXML();

Expected result:
----------------
<?xml version="1.0"?>
<HTML>
  <HEAD>
    <TITLE>
      This is the title
    </TITLE>
  </HEAD>
</HTML>


Actual result:
--------------
<?xml version="1.0"?>
<HTML />

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-26 12:23 UTC] chregu@php.net
Works for me on Linux... Can someone revalidate that on windows?
 [2004-07-26 12:33 UTC] tony2001@php.net
I can reproduce it with PHP 5.1.0-dev (cli) (built: Jul 26 2004 08:30:28) under Win2k.
 [2004-07-26 13:49 UTC] rrichards@php.net
I am unable to reproduce this under W2K and XP (using snaps and debug builds). Can someone who can reproduce this try var_dumping that vars after each line as well as doing a saveXML() on the doc each time to try to pinpoint where the problem lies. libxml version is irrelevant as I also tried from 2.5.11 - 2.6.11
 [2004-07-26 14:04 UTC] tony2001@php.net
Done.
Still using latest PHP-CLI from PHP5.1 snapshot under Win2k - sorry, no XP or any other Win32 system around here.

The code:
-----
<?
var_dump($doc = new DOMDocument("1.0"));
echo $doc->saveXML();
var_dump($root = $doc->createElement("HTML"));
echo $doc->saveXML();
var_dump($root = $doc->appendChild($root));
echo $doc->saveXML();
var_dump($head = $doc->createElement("HEAD"));
echo $doc->saveXML();
var_dump($head = $root->appendChild($head));
echo $doc->saveXML();
var_dump($title = $doc->createElement("TITLE"));
echo $doc->saveXML();
var_dump($title = $head->appendChild($title));
echo $doc->saveXML();
var_dump($text = $doc->createTextNode("This is the title"));
echo $doc->saveXML();
var_dump($text = $title->appendChild($text));
echo $doc->saveXML();
?>
-----

The output:
-----
object(DOMDocument)#2 (0) {
}
<?xml version="1.0"?>
object(DOMElement)#3 (0) {
}
<?xml version="1.0"?>
object(DOMElement)#3 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMElement)#4 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMElement)#4 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMElement)#5 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMElement)#5 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMText)#6 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMText)#6 (0) {
}
<?xml version="1.0"?>
<HTML/>
-----

The same code under Linux outputs this:
-----
object(DOMDocument)#1 (0) {
}
<?xml version="1.0"?>
object(DOMElement)#2 (0) {
}
<?xml version="1.0"?>
object(DOMElement)#2 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMElement)#3 (0) {
}
<?xml version="1.0"?>
<HTML/>
object(DOMElement)#3 (0) {
}
<?xml version="1.0"?>
<HTML><HEAD/></HTML>
object(DOMElement)#4 (0) {
}
<?xml version="1.0"?>
<HTML><HEAD/></HTML>
object(DOMElement)#4 (0) {
}
<?xml version="1.0"?>
<HTML><HEAD><TITLE/></HEAD></HTML>
object(DOMText)#5 (0) {
}
<?xml version="1.0"?>
<HTML><HEAD><TITLE/></HEAD></HTML>
object(DOMText)#5 (0) {
}
<?xml version="1.0"?>
<HTML><HEAD><TITLE>This is the title</TITLE></HEAD></HTML>
-----

I could try it with Win32 debug build too, if you tell me where I can get it.
 [2004-07-26 14:14 UTC] rrichards@php.net
Check your php.ini file and see if zend.ze1_compatibility_mode = On also change error_reporting to: error_reporting  =  E_ALL|E_STRICT

run it again, then if compat was on, change to off and run again.

 [2004-07-26 14:22 UTC] tony2001@php.net
Yep, it was On. Turning it Off solves the problem.

With compatibility On and error_reporting E_ALL|E_STRICT the code outputs:
--
Strict Standards: Implicit cloning object of class 'DOMDocument' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test
object(DOMDocument)#2 (0) {
}
<?xml version="1.0"?>

Strict Standards: Implicit cloning object of class 'DOMElement' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test.
object(DOMElement)#3 (0) {
}
<?xml version="1.0"?>

Strict Standards: Implicit cloning object of class 'DOMElement' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test.
object(DOMElement)#3 (0) {
}
<?xml version="1.0"?>
<HTML/>

Strict Standards: Implicit cloning object of class 'DOMElement' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test.
object(DOMElement)#4 (0) {
}
<?xml version="1.0"?>
<HTML/>

Strict Standards: Implicit cloning object of class 'DOMElement' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test.
object(DOMElement)#4 (0) {
}
<?xml version="1.0"?>
<HTML/>

Strict Standards: Implicit cloning object of class 'DOMElement' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test.
object(DOMElement)#5 (0) {
}
<?xml version="1.0"?>
<HTML/>

Strict Standards: Implicit cloning object of class 'DOMElement' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test.
object(DOMElement)#5 (0) {
}
<?xml version="1.0"?>
<HTML/>

Strict Standards: Implicit cloning object of class 'DOMText' because of 'zend.ze1_compatibility_mode' in E:\ftp\dom.test.php
object(DOMText)#6 (0) {
}
<?xml version="1.0"?>
<HTML/>
--
 [2004-08-11 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 05:01:28 2024 UTC