php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18927 foreach corrupting array contents
Submitted: 2002-08-15 17:12 UTC Modified: 2002-08-16 10:18 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: mattc at wselectric dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4.2.2 OS: Slackware Linux 7.1.0
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: mattc at wselectric dot com
New email:
PHP Version: OS:

 

 [2002-08-15 17:12 UTC] mattc at wselectric dot com
Running my sample script with the loop set up to 65534 times will run without corrupting the array $a.  If you run it as 65535 times or more, the array is corrupted, and the value of $b becomes an array, which then causes the following warnings to be generated:

PHP Warning:  Illegal offset type in /home/web/dev/docs/lookup/bug.php on line 9

Obviously the foreach and array assignments should not be corrupting the contents of array $a.

Sample script:

<script language="php">
$a = array(1);
foreach($a as $b)
{
  for($c = 0; $c < 65535; $c++)
  {
    $d = 1;
    $e[$d][] = array($b, $c);
    $f[$b][$c][] = $d;
  }
}
</script>
done

Configure command:

./configure \
--with-mysql=/usr/local/mysql \
--with-apxs=/usr/local/apache/bin/apxs \
--enable-ftp \
--enable-track-vars \
--enable-versioning \
--with-zlib

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-15 17:15 UTC] mattc at wselectric dot com
I originally experienced this problem on version 4.1.2 (same configure options), before upgrading -- only to find the problem still existed.
 [2002-08-16 10:18 UTC] kalowsky@php.net
It's not really a problem, or a bug.  You've hit the maximum value of a short int, which is how the Zend engine marks references.  The ZendEngine2 fixes, this but I'm doubtful you'll see this fixed in the current ZE1.  
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 15:01:27 2025 UTC