ID: 41582 Updated by: [EMAIL PROTECTED] Reported By: judas dot iscariote at gmail dot com -Status: Assigned +Status: Feedback Bug Type: SimpleXML related Operating System: Any PHP Version: 5CVS-2007-06-04 (CVS) Assigned To: dmitry New Comment:
The warning in first case is right. You cannot add element with index 1. In following examples you try to set XML attribute with name '2.5' and '0' and add somthing to this attribute. It is not possible to add something to attribute and engine told you that "Indirect modification of overloaded element of SimpleXMLElement has no effect". Memory leaks in such situation are expected. The only thing that I can do - prevent creaton of attributes with numeric names. Previous Comments: ------------------------------------------------------------------------ [2007-06-18 13:39:04] [EMAIL PROTECTED] Dmitry: new comment added that may need your attention ------------------------------------------------------------------------ [2007-06-15 06:32:25] judas dot iscariote at gmail dot com Dmitry, first thanks for taking care of correcting the leak.. however.. now a funny warning is raised !! $xml->movie[1]->characters->character[]->name = 'Miss Coder'; causes : Warning: main(): (main ? x_X) Cannot add element movie number 1 when only 0 such elements exist in...(this part is correct though) that's not so annoying or critical and we can live with it, however does not look good. Addtionally I gave this stuff a better test now.. and Im still able to find some good as well edge/wrong cases where this stuff needs improvement. for example: $xml->movie[2.5]->characters->character[0]->name = ''; leaks memory as well. this is bad code of course ;) however I think this raises the real issue.. IMHO the code should check if the element number is >= 0 and an integer (not a float,maybe cast it to integer? and or emit warning/notice when the wrong type is used...) other case, that "looks" valid. // the string '0'; $xml->movie['0']->characters->character[0]->name = ''; leaks memory and emits... Notice: Indirect modification of overloaded element of SimpleXMLElement has no effect in .. but 0 as an integer works fine :-) ------------------------------------------------------------------------ [2007-06-13 13:53:02] [EMAIL PROTECTED] This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. ------------------------------------------------------------------------ [2007-06-06 11:28:56] [EMAIL PROTECTED] Well, there are some cases which cannot be fixed at all. Fortunately they only happen when the code is b0rked, so I don't think it's critical. Markus, can you think of any solution for the leak? ------------------------------------------------------------------------ [2007-06-06 10:53:13] judas dot iscariote at gmail dot com fix works. but leaks memory in the above situation. $xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?> <collection></collection>'); $xml->movie[1]->characters->character[]->name = 'Miss Coder'; Zend/zend_execute.c(1249) : Freeing 0x00C97DA0 (24 bytes), script=simplecrashes.php === Total 1 memory leaks detected === ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/41582 -- Edit this bug report at http://bugs.php.net/?id=41582&edit=1