Doc #65771 [NEW]: Example for DOMNode::removeChild() throws error
From: krewecherl at gmail dot com
Operating system:
PHP version: Irrelevant
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:Example for DOMNode::removeChild() throws error
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 bug report at https://bugs.php.net/bug.php?id=65771&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65771&r=trysnapshot54
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65771&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65771&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65771&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65771&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65771&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65771&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65771&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65771&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65771&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=65771&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=65771&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65771&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65771&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65771&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65771&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65771&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65771&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65771&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65771&r=mysqlcfg
Thread (2 messages)
- krewecherl at gmail dot com