php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39164 SimpleXML : foreach create new node
Submitted: 2006-10-16 11:49 UTC Modified: 2006-12-13 03:07 UTC
Votes:6
Avg. Score:4.3 ± 0.7
Reproduced:4 of 5 (80.0%)
Same Version:3 (75.0%)
Same OS:0 (0.0%)
From: php at bouchery dot com Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.1.6 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at bouchery dot com
New email:
PHP Version: OS:

 

 [2006-10-16 11:49 UTC] php at bouchery dot com
Description:
------------
When using "foreach" on inexisting node, a new node is create.

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

$xml = simplexml_load_string('<root><a>Node a</a></root>');

foreach( $xml->b as $b );

echo $xml->asXML();

?>

Expected result:
----------------
<?xml version="1.0"?>
<root><a>Node a</a></root>

Actual result:
--------------
<?xml version="1.0"?>
<root><a>Node a</a><b/></root>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-16 15:57 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 [2006-10-16 16:14 UTC] php at bouchery dot com
I didn't see that in the documentation.
Even if it's written, it's a strange behaviour and shoud be a change request.

Reading data should not modify it.
 [2006-11-20 21:46 UTC] php at bouchery dot com
If there is no nodes, I browse like an array, no data is display, but a node was created. If I do it twice, it display something !

Browsing tree MUST NOT create node.

Look at this :

<?php
$xml = simplexml_load_string('<root></root>');
foreach( $xml->a as $a ) echo "a = $a\n";
foreach( $xml->a as $a ) echo "a = $a\n";
?>

A the second time, it display : "a ="

Sorry to insist, but it is not "normal" (and I can't see that in the documentation !!).
 [2006-12-12 23:37 UTC] joshi at sencore dot com
After an afternoon of research I have discovered that:
  The resolution to Bug #35785 caused this problem.
  CVS Revision 1.192 (by Helly) was the commit.

I have to agree with php at bouchery dot com that this is unfortunate behavior.  Who would expect that their structure would change just because they read it?
 [2006-12-13 03:07 UTC] iliaa@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is intended behavior.
 [2012-06-22 19:22 UTC] matteosistisette at gmail dot com
It's funny that this was insistingly claimed to be "intended behavior" and "not a 
bug" and then was silently fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC