[php-src] Issue #9240: DomDocument - same object id relates to different class

From: Date: Wed, 03 Aug 2022 12:01:05 +0000
Subject: [php-src] Issue #9240: DomDocument - same object id relates to different class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242112@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9240 Author: jifer ### Description The following code: ```php <?php final class DD extends \DOMDocument { public static function create() { $dom = new self(); $root = $dom->createElement('rootelement'); $dom->appendChild($root); $firstChild = $dom->firstChild; var_dump( spl_object_id($firstChild->ownerDocument), // int(1) get_class($firstChild->ownerDocument), // string(2) "DD" - this is correct ); return $firstChild; } public function myMethod(){} } $dd = DD::create(); var_dump( spl_object_id($dd->ownerDocument), // int(1) get_class($dd->ownerDocument), // string(11) "DOMDocument" - this is incorrect // $dd->ownerDocument->myMethod() // This will rise exception as myMethod doesn not exist on \DomDocument ); ``` Resulted in this output: ``` int(1) string(2) "DD" int(1) string(11) "DOMDocument" ``` But I expected this output instead: ``` int(1) string(2) "DD" int(1) string(2) "DD" ``` Both var_dumps operates on same object (dom->firstChild->ownerDocument) but when out of class scope it returns main class (DomDocument) instead of extension class (DD). It seems I can reproduce it only when creating object via static method. https://onlinephp.io/c/5d173 ### PHP Version 8.2.0beta1, 8.1.9, 7.4.30 ### Operating System _No response_

« previous php.bugs (#242112) next »