Re: [PHP] Destructor not called when extending SimpleXMLElement
Thanks Erwin and Matijn. On 2 July 2012 17:32, Matijn Woudt wrote: > This is most likely a bug in PHP. A deconstructor is called when there > are no references left to the object. Since this class uses the libXML > library, it is likely that there are still references from the libXML > open on the object, which is why it will never be destroyed. > Anyway, you should report this bug to the PHP devs (at bugs.php.net). Yes, that sounds plausible. As a quick hack, I tried adding a destructor to the SimpleXMLElement extension, but that wasn't called either. I'll submit a bug report. > If you really need this, it's probably best to create a class that > does not really extend SimpleXMLElement, but you create one inside the > constructor, and just forward all function calls to the > SimpleXMLElement object you've created in the constructor. I've been playing with that today, and it looks like a workable solution. Thanks for your help! Nick. -- Nick Chalk. Loadbalancer.org Ltd. Phone: +44 (0)870 443 8779 http://www.loadbalancer.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Destructor not called when extending SimpleXMLElement
On Mon, Jul 2, 2012 at 1:58 PM, Nick Chalk wrote: > Afternoon all. > > I seem to be having a little trouble with extending the > SimpleXMLElement class. I would like to add a destructor to the > subclass, but am finding that it is not called. > > Attached is a minimal demonstration of the problem. The XMLConfig > class extends SimpleXMLElement, and its destructor is not called. The > XMLConfig2 class, which does not use inheritance, does have its > destructor called. > > The test platform is CentOS 6.2, with PHP version 5.3.3. > > What am I missing? > > Thanks for your help. > Nick. Hi Nick, This is most likely a bug in PHP. A deconstructor is called when there are no references left to the object. Since this class uses the libXML library, it is likely that there are still references from the libXML open on the object, which is why it will never be destroyed. Anyway, you should report this bug to the PHP devs (at bugs.php.net). If you really need this, it's probably best to create a class that does not really extend SimpleXMLElement, but you create one inside the constructor, and just forward all function calls to the SimpleXMLElement object you've created in the constructor. - Matijn -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Destructor not called when extending SimpleXMLElement
Interesting problem. I would expect it to work too. I assume it is a bug. 2012/7/2 Nick Chalk > Afternoon all. > > I seem to be having a little trouble with extending the > SimpleXMLElement class. I would like to add a destructor to the > subclass, but am finding that it is not called. > > Attached is a minimal demonstration of the problem. The XMLConfig > class extends SimpleXMLElement, and its destructor is not called. The > XMLConfig2 class, which does not use inheritance, does have its > destructor called. > > The test platform is CentOS 6.2, with PHP version 5.3.3. > > What am I missing? > > Thanks for your help. > Nick. > > -- > Nick Chalk. > > Loadbalancer.org Ltd. > Phone: +44 (0)870 443 8779 > http://www.loadbalancer.org/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >