php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #65771 Example for DOMNode::removeChild() throws error
Submitted: 2013-09-27 02:45 UTC Modified: 2013-10-02 19:42 UTC
From: krewecherl at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: krewecherl at gmail dot com
New email:
PHP Version: OS:

 

 [2013-09-27 02:45 UTC] krewecherl at gmail dot com
Description:
------------
The manual page for DOMNode::removeChild() states:

"After calling this method, the DOMNode::$namespaceURI property on the parent 
node will be reset to NULL. Above example shows how to work around it."

http://www.php.net/manual/en/domnode.removechild.php

The example recommends storing the old value of $parentNode->namespaceURI and 
restoring it after the removeChild() call. IMHO this sounds more like something 
that should be fixed rather than documented, but more to the point, I could not 
reproduce it on several different PHP versions. On the contrary, the recommended 
solution throws the error "Cannot write property".

It appears that this has been fixed in a past version.

Related bug: https://bugs.php.net/bug.php?id=53083

Test script:
---------------
$xml = '<?xml version="1.0" encoding="UTF-8"?>'
     . '<b:book xmlns:b="urn:irrelevant">'
     .    '<b:chapter>Once upon a time</b:chapter>'
     . '</b:book>';

$doc = new DOMDocument();
$doc->loadXML($xml);

$book = $doc->documentElement;
$chapter = $book->getElementsByTagName("chapter")->item(0);
echo "book nsURI before: ", $book->namespaceURI, "\n";
  // prints "book nsURI before: urn:irrelevant"

$nsuri = $book->namespaceURI;
$book->removeChild($chapter);
echo "book nsURI after: ", $book->namespaceURI, "\n";
  // prints "book nsURI after: urn:irrelevant"

// fails with "Cannot write property"
//$book->namespaceURI = $nsuri;


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-02 19:41 UTC] krakjoe@php.net
Automatic comment from SVN on behalf of krakjoe
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=331645
Log: fix for #65771, removed old misleading information
 [2013-10-02 19:42 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2013-10-02 19:42 UTC] krakjoe@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

Thankyou for your input, documentation updated.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 04:00:02 2026 UTC