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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
24 + 18 = ?
Subscribe to this entry?

 
 [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

Pull Requests

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: Thu Oct 31 23:01:28 2024 UTC