3v4l.org

run code in 200+ PHP versions simultaneously
<?php class CustomDOMDocument extends DOMDocument { } function localScope() { $doc = new CustomDOMDocument; $doc->loadHtml('<p>Test123</p>'); $xpath = new DOMXPath($doc); return $xpath; } $doc = new CustomDOMDocument; $doc->loadHtml('<p>Test123</p>'); $xpath = new DOMXPath($doc); var_dump(get_class($xpath->document)); $xpath = new DOMXPath(new CustomDOMDocument); var_dump(get_class($xpath->document)); $xpath = localScope(); var_dump(get_class($xpath->document));
based on obo6S
Output for 5.6.0 - 7.4.0
string(17) "CustomDOMDocument" string(11) "DOMDocument" string(11) "DOMDocument"