Bug #73252 [NEW]: DOMXPath: doc passed in constructor not always equals $xpath->document.

From: Date: Wed, 05 Oct 2016 12:41:56 +0000
Subject: Bug #73252 [NEW]: DOMXPath: doc passed in constructor not always equals $xpath->document.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-204477@lists.php.net to get a copy of this message
From: arjen at parse dot nl Operating system: Linux PHP version: 7.0.11 Package: DOM XML related Bug Type: Bug Bug description:DOMXPath: doc passed in constructor not always equals $xpath->document. Description: ------------ When passing an object CustomDOMDocument extending DOMDocument as the DOMXPath object, the document property of DOMXpath is of type CustomDOMDocument. As soon as the original document is destructed (because of scope), a clone of the object is stored internally, but with type DOMDocument and not the CustomDOMDocument class. See https://3v4l.org/XLInV Test script: --------------- <?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)); Expected result: ---------------- string(17) "CustomDOMDocument" string(17) "CustomDOMDocument" string(17) "CustomDOMDocument" Actual result: -------------- string(17) "CustomDOMDocument" string(11) "DOMDocument" string(11) "DOMDocument" -- Edit bug report at https://bugs.php.net/bug.php?id=73252&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=73252&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=73252&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=73252&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=73252&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=73252&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=73252&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=73252&r=needscript Try newer version: https://bugs.php.net/fix.php?id=73252&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=73252&r=support Expected behavior: https://bugs.php.net/fix.php?id=73252&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=73252&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=73252&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=73252&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=73252&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=73252&r=dst IIS Stability: https://bugs.php.net/fix.php?id=73252&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=73252&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=73252&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=73252&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=73252&r=mysqlcfg

« previous php.bugs (#204477) next »