[PHP-BUG] Bug #51846 [NEW]: SimpleXMLElement iterator produces unexpected results

2010-05-17 Thread henning at glatter-gotz dot com
From: 
Operating system: windows xp
PHP version:  5.3.2
Package:  SimpleXML related
Bug Type: Bug
Bug description:SimpleXMLElement iterator produces unexpected results

Description:

When loading an xml document with simplexml_load_string() that contains
2500 or 

more child elements, iterating over these 

with a foreach loop and pushing results into an array results in 4998 array


entries, when only 2500 are expected. See sample 

code for the exact conditions under which this occurs.



There are two foreach loops, the first behaves as expected and results in
an 

array of exactly 2500 objects of type A, 

whereas the second foreach loop that instantiates an object of type B in
each 

iteration ends up being of size 4998.



Note that the object B takes two parameters in the constructor. This
behavior is 

only exhibited if both parameters are 

arrays. If one is changed to an int for example the code runs as expected.



Also, if the xml files contains 2499 elements or less, the code also works
as 

expected.

Executed on the command line in the following environments:



1) Windows XP, PHP 5.3.1 (cli) (built: Nov 20 2009 17:26:32) -> FAIL

2) Windows XP, PHP 5.3.2 (cli) (built: Mar  3 2010 19:40:13) -> FAIL

3) PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: Jan  6 2010


22:56:44) -> SUCCESS



Setups 1 and 3 are production environments and have slightly modified
php.ini 

files. Setup 2 is an "out of the box" download 

of VC6 x86 Thread Safe (2010-Mar-04 20:11:08) from 

http://windows.php.net/download/. No changes were made to it.

Test script:
---
class A

{}



class B

{

   protected $v1;

   protected $v2;

   

   public function __construct($v1, $v2) {

  $this->v1 = $v1;

  $this->v2 = $v2;

   }

}



$xml_string = "";



for ($i = 0; $i < 2500; ++$i) {

   $xml_string .= "bla";

}



$xml_string .= "";

$xml = simplexml_load_string($xml_string);

$a1 = array();

$a2 = array();



foreach ($xml->row as $r) {

   $a1[] = new A();

}



foreach ($xml->row as $r) {

   $val1 = array();

   $val2 = array();

   $a2[] = new B($val1, $val2);

}



echo 'count(a1) = '.count($a1).PHP_EOL;

echo 'count(a2) = '.count($a2).PHP_EOL;

Expected result:

count(a1) = 2500

count(a2) = 2500

Actual result:
--
count(a1) = 2500

count(a2) = 4998

-- 
Edit bug report at http://bugs.php.net/bug.php?id=51846&edit=1
-- 
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51846&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51846&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51846&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51846&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=51846&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51846&r=alreadyfixed
Need backtrace:  
http://bugs.php.net/fix.php?id=51846&r=needtrace
Need Reproduce Script:   
http://bugs.php.net/fix.php?id=51846&r=needscript
Try newer version:   
http://bugs.php.net/fix.php?id=51846&r=oldversion
Not developer issue: 
http://bugs.php.net/fix.php?id=51846&r=support
Expected behavior:   
http://bugs.php.net/fix.php?id=51846&r=notwrong
Not enough info: 
http://bugs.php.net/fix.php?id=51846&r=notenoughinfo
Submitted twice: 
http://bugs.php.net/fix.php?id=51846&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51846&r=globals
PHP 4 support discontinued:  http://bugs.php.net/fix.php?id=51846&r=php4
Daylight Savings:http://bugs.php.net/fix.php?id=51846&r=dst
IIS Stability:   
http://bugs.php.net/fix.php?id=51846&r=isapi
Install GNU Sed: 
http://bugs.php.net/fix.php?id=51846&r=gnused
Floating point limitations:  
http://bugs.php.net/fix.php?id=51846&r=float
No Zend Extensions:  
http://bugs.php.net/fix.php?id=51846&r=nozend
MySQL Configuration Error:   
http://bugs.php.net/fix.php?id=51846&r=mysqlcfg



Bug #51846 [Opn]: SimpleXMLElement iterator produces unexpected results

2010-05-17 Thread henning at glatter-gotz dot com
Edit report at http://bugs.php.net/bug.php?id=51846&edit=1

 ID:   51846
 User updated by:  henning at glatter-gotz dot com
 Reported by:  henning at glatter-gotz dot com
 Summary:  SimpleXMLElement iterator produces unexpected results
 Status:   Open
 Type: Bug
 Package:  SimpleXML related
 Operating System: windows xp
 PHP Version:  5.3.2

 New Comment:

Now also tested on PHP 5.3.2-1ubuntu4.1 with Suhosin-Patch (cli) (built:
May  4 2010 06:56:22). It fails with the same result as on Windows.


Previous Comments:

[2010-05-18 02:37:26] henning at glatter-gotz dot com

Description:

When loading an xml document with simplexml_load_string() that contains
2500 or 

more child elements, iterating over these 

with a foreach loop and pushing results into an array results in 4998
array 

entries, when only 2500 are expected. See sample 

code for the exact conditions under which this occurs.



There are two foreach loops, the first behaves as expected and results
in an 

array of exactly 2500 objects of type A, 

whereas the second foreach loop that instantiates an object of type B in
each 

iteration ends up being of size 4998.



Note that the object B takes two parameters in the constructor. This
behavior is 

only exhibited if both parameters are 

arrays. If one is changed to an int for example the code runs as
expected.



Also, if the xml files contains 2499 elements or less, the code also
works as 

expected.

Executed on the command line in the following environments:



1) Windows XP, PHP 5.3.1 (cli) (built: Nov 20 2009 17:26:32) -> FAIL

2) Windows XP, PHP 5.3.2 (cli) (built: Mar  3 2010 19:40:13) -> FAIL

3) PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: Jan  6
2010 

22:56:44) -> SUCCESS



Setups 1 and 3 are production environments and have slightly modified
php.ini 

files. Setup 2 is an "out of the box" download 

of VC6 x86 Thread Safe (2010-Mar-04 20:11:08) from 

http://windows.php.net/download/. No changes were made to it.

Test script:
---
class A

{}



class B

{

   protected $v1;

   protected $v2;

   

   public function __construct($v1, $v2) {

  $this->v1 = $v1;

  $this->v2 = $v2;

   }

}



$xml_string = "";



for ($i = 0; $i < 2500; ++$i) {

   $xml_string .= "bla";

}



$xml_string .= "";

$xml = simplexml_load_string($xml_string);

$a1 = array();

$a2 = array();



foreach ($xml->row as $r) {

   $a1[] = new A();

}



foreach ($xml->row as $r) {

   $val1 = array();

   $val2 = array();

   $a2[] = new B($val1, $val2);

}



echo 'count(a1) = '.count($a1).PHP_EOL;

echo 'count(a2) = '.count($a2).PHP_EOL;

Expected result:

count(a1) = 2500

count(a2) = 2500

Actual result:
--
count(a1) = 2500

count(a2) = 4998






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51846&edit=1


Bug #51846 [Opn]: SimpleXMLElement iterator produces unexpected results

2010-05-17 Thread henning at glatter-gotz dot com
Edit report at http://bugs.php.net/bug.php?id=51846&edit=1

 ID:   51846
 User updated by:  henning at glatter-gotz dot com
 Reported by:  henning at glatter-gotz dot com
 Summary:  SimpleXMLElement iterator produces unexpected results
 Status:   Open
 Type: Bug
 Package:  SimpleXML related
-Operating System: windows xp
+Operating System: windows xp / Linux
 PHP Version:  5.3.2

 New Comment:

Added Linux (Ubuntu) to the OS field.


Previous Comments:

[2010-05-18 02:53:34] henning at glatter-gotz dot com

Now also tested on PHP 5.3.2-1ubuntu4.1 with Suhosin-Patch (cli) (built:
May  4 2010 06:56:22). It fails with the same result as on Windows.


[2010-05-18 02:37:26] henning at glatter-gotz dot com

Description:

When loading an xml document with simplexml_load_string() that contains
2500 or 

more child elements, iterating over these 

with a foreach loop and pushing results into an array results in 4998
array 

entries, when only 2500 are expected. See sample 

code for the exact conditions under which this occurs.



There are two foreach loops, the first behaves as expected and results
in an 

array of exactly 2500 objects of type A, 

whereas the second foreach loop that instantiates an object of type B in
each 

iteration ends up being of size 4998.



Note that the object B takes two parameters in the constructor. This
behavior is 

only exhibited if both parameters are 

arrays. If one is changed to an int for example the code runs as
expected.



Also, if the xml files contains 2499 elements or less, the code also
works as 

expected.

Executed on the command line in the following environments:



1) Windows XP, PHP 5.3.1 (cli) (built: Nov 20 2009 17:26:32) -> FAIL

2) Windows XP, PHP 5.3.2 (cli) (built: Mar  3 2010 19:40:13) -> FAIL

3) PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: Jan  6
2010 

22:56:44) -> SUCCESS



Setups 1 and 3 are production environments and have slightly modified
php.ini 

files. Setup 2 is an "out of the box" download 

of VC6 x86 Thread Safe (2010-Mar-04 20:11:08) from 

http://windows.php.net/download/. No changes were made to it.

Test script:
---
class A

{}



class B

{

   protected $v1;

   protected $v2;

   

   public function __construct($v1, $v2) {

  $this->v1 = $v1;

  $this->v2 = $v2;

   }

}



$xml_string = "";



for ($i = 0; $i < 2500; ++$i) {

   $xml_string .= "bla";

}



$xml_string .= "";

$xml = simplexml_load_string($xml_string);

$a1 = array();

$a2 = array();



foreach ($xml->row as $r) {

   $a1[] = new A();

}



foreach ($xml->row as $r) {

   $val1 = array();

   $val2 = array();

   $a2[] = new B($val1, $val2);

}



echo 'count(a1) = '.count($a1).PHP_EOL;

echo 'count(a2) = '.count($a2).PHP_EOL;

Expected result:

count(a1) = 2500

count(a2) = 2500

Actual result:
--
count(a1) = 2500

count(a2) = 4998






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51846&edit=1


Bug #51846 [Fbk->Opn]: SimpleXMLElement iterator produces unexpected results

2010-05-17 Thread henning at glatter-gotz dot com
Edit report at http://bugs.php.net/bug.php?id=51846&edit=1

 ID:   51846
 User updated by:  henning at glatter-gotz dot com
 Reported by:  henning at glatter-gotz dot com
 Summary:  SimpleXMLElement iterator produces unexpected results
-Status:   Feedback
+Status:   Open
 Type: Bug
 Package:  SimpleXML related
 Operating System: windows xp / Linux
 PHP Version:  5.3.2

 New Comment:

For windows I downloaded the latest available VC6 x86 Thread Safe
(2010-Mar-04 

20:11:08) binaries, and tried it (see original report).

I cannot build from Source on Linux, I do not have sufficient access to
a system 

to do that. Sorry.

But I did test on two different OS' and 3 different versions of PHP.


Previous Comments:

[2010-05-18 02:58:11] fel...@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/




[2010-05-18 02:56:11] henning at glatter-gotz dot com

Added Linux (Ubuntu) to the OS field.


[2010-05-18 02:53:34] henning at glatter-gotz dot com

Now also tested on PHP 5.3.2-1ubuntu4.1 with Suhosin-Patch (cli) (built:
May  4 2010 06:56:22). It fails with the same result as on Windows.


[2010-05-18 02:37:26] henning at glatter-gotz dot com

Description:

When loading an xml document with simplexml_load_string() that contains
2500 or 

more child elements, iterating over these 

with a foreach loop and pushing results into an array results in 4998
array 

entries, when only 2500 are expected. See sample 

code for the exact conditions under which this occurs.



There are two foreach loops, the first behaves as expected and results
in an 

array of exactly 2500 objects of type A, 

whereas the second foreach loop that instantiates an object of type B in
each 

iteration ends up being of size 4998.



Note that the object B takes two parameters in the constructor. This
behavior is 

only exhibited if both parameters are 

arrays. If one is changed to an int for example the code runs as
expected.



Also, if the xml files contains 2499 elements or less, the code also
works as 

expected.

Executed on the command line in the following environments:



1) Windows XP, PHP 5.3.1 (cli) (built: Nov 20 2009 17:26:32) -> FAIL

2) Windows XP, PHP 5.3.2 (cli) (built: Mar  3 2010 19:40:13) -> FAIL

3) PHP 5.2.10-2ubuntu6.4 with Suhosin-Patch 0.9.7 (cli) (built: Jan  6
2010 

22:56:44) -> SUCCESS



Setups 1 and 3 are production environments and have slightly modified
php.ini 

files. Setup 2 is an "out of the box" download 

of VC6 x86 Thread Safe (2010-Mar-04 20:11:08) from 

http://windows.php.net/download/. No changes were made to it.

Test script:
---
class A

{}



class B

{

   protected $v1;

   protected $v2;

   

   public function __construct($v1, $v2) {

  $this->v1 = $v1;

  $this->v2 = $v2;

   }

}



$xml_string = "";



for ($i = 0; $i < 2500; ++$i) {

   $xml_string .= "bla";

}



$xml_string .= "";

$xml = simplexml_load_string($xml_string);

$a1 = array();

$a2 = array();



foreach ($xml->row as $r) {

   $a1[] = new A();

}



foreach ($xml->row as $r) {

   $val1 = array();

   $val2 = array();

   $a2[] = new B($val1, $val2);

}



echo 'count(a1) = '.count($a1).PHP_EOL;

echo 'count(a2) = '.count($a2).PHP_EOL;

Expected result:

count(a1) = 2500

count(a2) = 2500

Actual result:
--
count(a1) = 2500

count(a2) = 4998






-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51846&edit=1


Bug #51846 [Opn]: SimpleXMLElement iterator produces unexpected results

2010-05-18 Thread henning at glatter-gotz dot com
Edit report at http://bugs.php.net/bug.php?id=51846&edit=1

 ID:   51846
 User updated by:  henning at glatter-gotz dot com
 Reported by:  henning at glatter-gotz dot com
 Summary:  SimpleXMLElement iterator produces unexpected results
 Status:   Open
 Type: Bug
 Package:  SimpleXML related
 Operating System: windows xp / Linux
 PHP Version:  5.3.2

 New Comment:

I agree, it is possible that this is indeed related or even the same

problem as 50670. I ran some more test on documents with more than

10k elements and there both of my test cases fail, even the one that

works for smaller sets.



Did not think to look for issues related to the script Engine, so I

did not find that bug.



Maybe you can mark this one as a dupe and I will vote on the 50670.



Thanks!


Previous Comments:

[2010-05-18 09:39:55] m...@php.net

Probably related to Bug #50670


[2010-05-18 03:15:02] henning at glatter-gotz dot com

For windows I downloaded the latest available VC6 x86 Thread Safe
(2010-Mar-04 

20:11:08) binaries, and tried it (see original report).

I cannot build from Source on Linux, I do not have sufficient access to
a system 

to do that. Sorry.

But I did test on two different OS' and 3 different versions of PHP.


[2010-05-18 02:58:11] fel...@php.net

Please try using this snapshot:

  http://snaps.php.net/php5.3-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/




[2010-05-18 02:56:11] henning at glatter-gotz dot com

Added Linux (Ubuntu) to the OS field.


[2010-05-18 02:53:34] henning at glatter-gotz dot com

Now also tested on PHP 5.3.2-1ubuntu4.1 with Suhosin-Patch (cli) (built:
May  4 2010 06:56:22). It fails with the same result as on Windows.




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/bug.php?id=51846


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51846&edit=1