php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41584 SimpleXML emits wrong spurious notice...
Submitted: 2007-06-04 10:09 UTC Modified: 2007-06-15 06:09 UTC
From: judas dot iscariote at gmail dot com Assigned: helly (profile)
Status: Closed Package: SimpleXML related
PHP Version: 5CVS-2007-06-04 (CVS) OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: judas dot iscariote at gmail dot com
New email:
PHP Version: OS:

 

 [2007-06-04 10:09 UTC] judas dot iscariote at gmail dot com
Description:
------------
[different problem, but a follow up of bug 41582


The following code emits a wrong notice, rendering this stuff more or less useless in write context...



Reproduce code:
---------------
<?php

$xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?> <collection></collection>');

$xml->movie[0]->characters->character[0]->name = 'Miss Coder';
$xml->movie[0]->characters->character[1]->name = 'ouch';

var_dump($xml->asXML());


Expected result:
----------------
string(%d) "<?xml version="1.0" standalone="yes"?>
<collection><movie><characters><character><name>Miss Coder</name></character><character><name>ouch</name></character></characters></movie></collection>
"

Actual result:
--------------
PHP Notice:  Indirect modification of overloaded element of SimpleXMLElement has no effect in /home/cristian/simplecrashes.php on line 6
string(151) "<?xml version="1.0" standalone="yes"?>
<collection><movie><characters><character><name>Miss Coder</name></character></characters></movie></collection>
"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-06-04 11:12 UTC] tony2001@php.net
IMO the warning is correct and the code is not.
I don't understand what you're trying to do with $object[0]->property - is this supposed to created a property named '0' and assign an empty object to it?
 [2007-06-04 12:06 UTC] tony2001@php.net
After a discussion with Christian, I do agree that there is something wrong with the logics SimpleXML uses.
When you use $obj->element[0] it actually uses $obj->element (well, I can see the reasoning, but it's a bit non-obvious). On the other hand, when you try to write $obj->element[1], the result is NULL 'cause there is no element #1.

I guess sxe_prop_dim_read() should automatically create elements when used with BP_VAR_W/BP_VAR_RW.
Marcus, what do you think about it?
 [2007-06-04 12:15 UTC] judas dot iscariote at gmail dot com
I can use

either :

$xml->movie[0]->addChild('character')->addChild('name', 'ouch');

or:

$xml->movie[0]->addChild('character')->name = 'ouch';

To create the second element and then keep working with

$xml->movie[n]->characters->character[n] -> foo = 'bar' as usual.

is just the operation the create a new (second) "character" automatically after the first element using [n] does not work.
 [2007-06-15 06:09 UTC] judas dot iscariote at gmail dot com
This bug was fixed in CVS among with #41582( thanks dmitry ;) )
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 22 02:01:28 2024 UTC