#46265 [NEW]: DOMNode should have a property that checks if it exists

From: Date: Thu, 09 Oct 2008 19:17:39 +0000
Subject: #46265 [NEW]: DOMNode should have a property that checks if it exists
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-129594@lists.php.net to get a copy of this message
From: josh at coady dot us Operating system: ubuntu 8.04.1 PHP version: 5.2.6 PHP Bug Type: DOM XML related Bug description: DOMNode should have a property that checks if it exists Description: ------------ DOMNode should have a property like $exists to check if the node still exists. This would be useful to avoid the "Node no longer exists" warning. We should be able to do something like $node->parentNode->removeChild($node); if($node->exists) { // use node .. } Reproduce code: --------------- $doc = DOMDocument::loadXML('<doc><x><a>1</a></x><x><a>1</a><y><a>1</a><a>0</a></y></x></doc>'); $nodes = $doc->getElementsByTagName('a'); $nodesToRemove = array(); foreach($nodes as $node) { if($node->nodeValue == 1) { $nodesToRemove[] = $node; $node->parentNode->removeChild($node); } } foreach($nodesToRemove as $node) { $node->parentNode->removeChild($node); } Expected result: ---------------- This is more of a feature request. I expect to change the last loop to something like foreach($nodesToRemove as $node) { if($node->exists) { $node->parentNode->removeChild($node); } } -- Edit bug report at http://bugs.php.net/?id=46265&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46265&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46265&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46265&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46265&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=46265&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46265&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46265&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46265&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46265&r=support Expected behavior: http://bugs.php.net/fix.php?id=46265&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46265&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46265&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46265&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46265&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46265&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46265&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46265&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46265&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46265&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46265&r=mysqlcfg

« previous php.bugs (#129594) next »