Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
--TEST-- Bug #36756 (DOMDocument::removeChild corrupts node) --EXTENSIONS-- dom --FILE-- <..
Decoded Output download
--TEST--
Bug #36756 (DOMDocument::removeChild corrupts node)
--EXTENSIONS--
dom
--FILE--
<?php
/* Node is preserved from removeChild */
$dom = new DOMDocument();
$dom->loadXML('<root><child/></root>');
$xpath = new DOMXpath($dom);
$node = $xpath->query('/root')->item(0);
echo $node->nodeName . "
";
$dom->removeChild($GLOBALS['dom']->firstChild);
echo "nodeType: " . $node->nodeType . "
";
/* Node gets destroyed during removeChild */
$dom->loadXML('<root><child/></root>');
$xpath = new DOMXpath($dom);
$node = $xpath->query('//child')->item(0);
echo $node->nodeName . "
";
$GLOBALS['dom']->removeChild($GLOBALS['dom']->firstChild);
try {
echo "nodeType: " . $node->nodeType . "
";
} catch (\Error $e) {
echo get_class($e) . ': ' . $e->getMessage() .\PHP_EOL;
}
?>
--EXPECT--
root
nodeType: 1
child
Error: Couldn't fetch DOMElement. Node no longer exists
Did this file decode correctly?
Original Code
--TEST--
Bug #36756 (DOMDocument::removeChild corrupts node)
--EXTENSIONS--
dom
--FILE--
<?php
/* Node is preserved from removeChild */
$dom = new DOMDocument();
$dom->loadXML('<root><child/></root>');
$xpath = new DOMXpath($dom);
$node = $xpath->query('/root')->item(0);
echo $node->nodeName . "\n";
$dom->removeChild($GLOBALS['dom']->firstChild);
echo "nodeType: " . $node->nodeType . "\n";
/* Node gets destroyed during removeChild */
$dom->loadXML('<root><child/></root>');
$xpath = new DOMXpath($dom);
$node = $xpath->query('//child')->item(0);
echo $node->nodeName . "\n";
$GLOBALS['dom']->removeChild($GLOBALS['dom']->firstChild);
try {
echo "nodeType: " . $node->nodeType . "\n";
} catch (\Error $e) {
echo get_class($e) . ': ' . $e->getMessage() .\PHP_EOL;
}
?>
--EXPECT--
root
nodeType: 1
child
Error: Couldn't fetch DOMElement. Node no longer exists
Function Calls
None |
Stats
MD5 | 28e5f6a14492398d6a477d945f5e85a3 |
Eval Count | 0 |
Decode Time | 84 ms |