php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43490 DOMDocument properties not respected when set in subclass extending DOMDocument
Submitted: 2007-12-03 22:51 UTC Modified: 2007-12-04 17:10 UTC
From: claus at phpmind dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.2.5 OS: Gentoo 2.6.23 / Apache 2.2.6
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: claus at phpmind dot net
New email:
PHP Version: OS:

 

 [2007-12-03 22:51 UTC] claus at phpmind dot net
Description:
------------
Follow-up on bug report ID #31934

Original report:
----------------
I made a subclass which extends the domdocument class. When i try to set
the formatOutput or preserveWhiteSpace property within this subclass, it
doesnt work. 

when i create a domdocument object and set it not through a subclass, it
works fine. I dont know if this is a bug?!


Initial response, rrichards@php.net
----------------
in order to get those properties set in your class constructor, you need
to call parent::__construct(); as your first line in your constructor.


Update:
----------------
Of course you need to run the constructor of the parent class - but that doesn't fix the problem. When using saveXML() on the subclass instance the format is still not formatted regardless of the setting of the subclass property, even if it was set by calling the parent's constructor first and then either:

a) setting the property directly, be it from the subclass instance or the $this internal key
b) using the __set() method called as parent::__set('formatOutput', true);

Both do not work. Please reconsider this bug report as it still appears to be a bug that's soon to be three years old. You were too quick to mark this as bogus - apparently you did not even try the reproduction code from Michael Mezger.

Reproduce code:
---------------
class guestbook extends domdocument {
  function guestbook($file){

    $this->preserveWhiteSpace = FALSE;
    $this->formatOutput = TRUE;   //format the guestbook.xml
    $this->load($file);  //load XML File
    $this->save($file);
		
  } 
}

$guestbook = new guestbook("test.xml");
var_dump($guestbook->preserveWhiteSpace); //echo: (boolean) true
var_dump($guestbook->formatOutput); //echo: (boolean) false

//This code above works
$guestbook2 = new domdocument();
$guestbook2->load("test.xml");
$guestbook2->preserveWhiteSpace = FALSE;
$guestbook2->formatOutput = TRUE;

var_dump($guestbook2->preserveWhiteSpace); //echo: (boolean) false
var_dump($guestbook2->formatOutput); //echo: (boolean) true

Expected result:
----------------
Would expect output to be formatted at least with one of the applied methods of setting the parent class (DOMDocument) properties, see description.

Actual result:
--------------
Output is not formatted (property formatOutput), whitespace is not preserved (property preserveWhitespace). Apparently the properties of the DOMDocument class are not respected when using a subclass which extends the DOMDocument class.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-04 17:10 UTC] rrichards@php.net
You completely ignored my response from previous bug and you didnt call the parent's constructor when you overrode it.

class guestbook extends domdocument {
  function guestbook($file){
    parent::__construct();
    $this->preserveWhiteSpace = FALSE;
    ...

alternatively set the props after loading the document. Either way you need the underlying document structure (created during construction - which you arent calling - or after a document is loaded) before setting those properties.

Still bogus because it works as it should.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 29 20:01:30 2024 UTC