Doc #65771 [Opn->Csd]: Example for DOMNode::removeChild() throws error

From: Date: Wed, 02 Oct 2013 19:42:31 +0000
Subject: Doc #65771 [Opn->Csd]: Example for DOMNode::removeChild() throws error
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-10358@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65771&edit=1

 ID:                 65771
 Updated by:         krakjoe@php.net
 Reported by:        krewecherl at gmail dot com
 Summary:            Example for DOMNode::removeChild() throws error
-Status:             Open
+Status:             Closed
 Type:               Documentation Problem
 Package:            Documentation problem
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        krakjoe
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2013-10-02 19:41:44] krakjoe@php.net

Automatic comment from SVN on behalf of krakjoe
Revision: http://svn.php.net/viewvc/?view=revision&revision=331645
Log: fix for #65771, removed old misleading information

------------------------------------------------------------------------
[2013-09-27 02:45:52] 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;



------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=65771&edit=1


Thread (2 messages)

« previous php.doc.bugs (#10358) next »