#33450 [NEW]: DOMNodes forget their class

From: Date: Thu, 23 Jun 2005 09:36:10 +0000
Subject: #33450 [NEW]: DOMNodes forget their class
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-80891@lists.php.net to get a copy of this message
From: arendjr at gmail dot com Operating system: Linux PHP version: 5.0.4 PHP Bug Type: Zend Engine 2 problem Bug description: DOMNodes forget their class Description: ------------ Whenever I create a class which inherits DOMElement, and I create an instance of this class, the type of the class is "forgotten" when the variable holding the instance goes out of scope, even though the actual instance should still exist as it is part of the DOM tree. So, what you get is that the inherited DOMElement still exists in the DOM tree, but the subclass instance is gone. Reproduce code: --------------- <?php class Widget extends DOMElement { public function __construct() { parent::__construct('p'); } public function say() { echo "I am a widget!\n"; } } $doc = new DOMDocument(); $doc->appendChild($html = new DOMElement('html')); $html->appendChild($body = new DOMElement('body')); $body->appendChild(new Widget()); $body->firstChild->say(); ?> Expected result: ---------------- It should say: "I am a widget!". You can get this expected result by changing the line: $body->appendChild(new Widget()); to: $body->appendChild($widget = new Widget()); this way, the widget will not get out of scope and the actual class is remembered. Actual result: -------------- You will get an error saying: "Fatal error: Call to undefined method DOMElement::say() in testcase.php on line 17" -- Edit bug report at http://bugs.php.net/?id=33450&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33450&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33450&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33450&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33450&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33450&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33450&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33450&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33450&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33450&r=support Expected behavior: http://bugs.php.net/fix.php?id=33450&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33450&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33450&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33450&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33450&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33450&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33450&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33450&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33450&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33450&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33450&r=mysqlcfg

« previous php.bugs (#80891) next »