php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36600 DOMDocument::loadXML() within derived class broken
Submitted: 2006-03-03 09:55 UTC Modified: 2006-03-03 16:25 UTC
From: georg at howen dot de Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.1.2 OS: Linux, Win XP
Private report: No CVE-ID: None
 [2006-03-03 09:55 UTC] georg at howen dot de
Description:
------------
If you extend DOMDocument and try to use DOMDocument::loadXML() on a new DOMDocument within the extended class, this function will return true instead of a new instance of DOMDocument.

Reproduce code:
---------------
<?php

class xDOMDocument extends DOMDocument {

	public function newDom($xml) {

		$internal_doc1 = new DOMDocument;
		$internal_doc1->loadXML($xml);
		print_r($internal_doc1);

		$internal_doc2 = DOMDocument::loadXML($xml);
		print_r($internal_doc2);

	}
}

$xml = '<def>Test</def>';
$dom = new xDOMDocument();
$dom->newDom($xml);


Expected result:
----------------
DOMDocument Object
(
)
DOMDocument Object
(
)

Actual result:
--------------
DOMDocument Object
(
)
1

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-03-03 10:20 UTC] bjori@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

DOMDocument::loadXML will return DOMDocument only when called staticly
 [2006-03-03 10:38 UTC] georg at howen dot de
Hi,

I thought I was aware of that. But isn't

$internal_doc2 = DOMDocument::loadXML($xml);

a static call to DOMDocument? That's the one that works fine _outside_ of a DOMDocument but not inside a class that extends DOMDocument.
 [2006-03-03 11:42 UTC] georg at howen dot de
Changed status back to open since I believe that 

$internal_doc2 = DOMDocument::loadXML($xml);

is a static call that does not return what it should. 

If I didn't get something right I am really sorry, but I still believe this is a bug.
 [2006-03-03 16:25 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

loadXML() is not a true static function. It is just allowed to be called statically. When called statically within a method of an instantiated DOMDocument object it acts as if the method had been called directly from the object itself rather than statically.
use the syntax as demonstrated by the behavior of $internal_doc1 creation in this case.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 18:01:34 2024 UTC