php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #20251 Can't assign values to array in loop.
Submitted: 2002-11-04 18:38 UTC Modified: 2002-11-05 19:01 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: director at misny dot com Assigned:
Status: Wont fix Package: Arrays related
PHP Version: 4.2.1 OS: linux 2.4.7-10enterprise #1 SMP
Private report: No CVE-ID: None
 [2002-11-04 18:38 UTC] director at misny dot com
I can't get values assigned to arrays inside a loop when loop repetition is high.

<?
$a=80000;
$b=1;
for($i=0; $i<$a; $i++){
	$c[$i]=$b;
}
echo count($c);
?>

Sometimes, this will run, sometimes, it won't.  Cutoff of at what number $a this script works varies.  Sometimes, it works when $a=70000, sometimes it won't.

This is with using (8)Xeon 700-2 processors with 2GB RAM on a very busy apache/php only server.  On our test machine (doing nothing) with (2) P4-1000 processors, $a= can be as high as 130000.

Am I just missing something?



Configure command:
'./configure' '--with-mysql=../mysql' '--with-apache=../apache_1.3.24' '--enable-track-vars' '--enable-mbstring'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-11-04 18:43 UTC] nicos@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.
 [2002-11-04 18:50 UTC] director at misny dot com
I apologize if you think this is not the appropriate place, but I had confered with a couple of other developers who experienced the same problem when this was run, so I figured it was a php bug.  I'll do more research (trying it on windows, maybe) and see what I come up with.  Sorry to waste your time.
 [2002-11-04 18:50 UTC] nicos@php.net
ilia said it was reproductile with any values larger than 66000
 [2002-11-04 19:12 UTC] director at misny dot com
The following works in place of array, so I'll try and see how much memory and CPU this uses.

<?
$a=1000000;
for($i=0; $i<$a; $i++){
	$d="ar".$i;
	$$d=$i;
}
echo $ar5943;
?>
 [2002-11-04 19:23 UTC] nicos@php.net
Okay, Please join a gdb backtrace.
 [2002-11-05 08:08 UTC] iliaa@php.net
In ZE1 use array_fill() to fill in an array with the same value, it'll be faster and work. In ZE2 your code will work fine as is, still array_fill() would probably be a better alternative.
 [2002-11-05 17:46 UTC] director at misny dot com
Thank you.  I don't know much about the development of Zend engine, so I guess I'll wait for ZE2 to be included in future release of PHP.

I had posted a bad sample code.  I wasn't trying to fill an array with the same value, so it should have been:


<?
$a=80000;
for($i=0; $i<$a; $i++){
	$c[$i]=$i;
}
echo count($c);
?>

And, by the way, this also crashes when $a gets too high or is coupled with another similar loop in the same script:

<?
$a=1000000;
for($i=0; $i<$a; $i++){
	$d="ar".$i;
	$$d=$i;
}
echo $ar5943;
?>


If these work in ZE2, should I bother to do a gdb backtrace using ZE1?
 [2002-11-05 19:01 UTC] iliaa@php.net
I've tried the last two examples you've provided. They work just fine on 4.2.3 and 4.3.0-pre2 on an SMP linux server.

Setting the status of the report back to Won't Fix based on the initial report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC