php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #46561 Warning:Cannot add element to the array as the next element is already occupied
Submitted: 2008-11-13 00:27 UTC Modified: 2008-12-09 12:52 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: jian at theorchard dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.6 OS: *
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: jian at theorchard dot com
New email:
PHP Version: OS:

 

 [2008-11-13 00:27 UTC] jian at theorchard dot com
Description:
------------
PHP Bugs: #41685 was not fixed in version 5.2.5 and 5.2.6.  I was able to reproduce the problem with this exact code from rob_nicholson at uk dot ibm dot com's example.

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

$arr = array();
$arr[0x80000000]=8;
$arr[0x7FFFFFFF]=1;
$arr[]="foo";
?>

Expected result:
----------------
array(3) {
  [-2147483648]=>
  int(8)
  [2147483647]=>
  int(1)
  [0]=>
  string(3) "foo"
}



Actual result:
--------------
PHP Warning:  array_push(): Cannot add element to the array as the next element is already occupied in C:\test.php on line 6
array(2) {
  [-2147483648]=>
  int(8)
  [2147483647]=>
  int(1)
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-14 18:24 UTC] lbarnaud@php.net
What was fixed in #41685 is that array_push() was not producing warnings in this case (the fix has added the warning in array_push()).
 [2008-11-14 20:52 UTC] jian at theorchard dot com
Ok.  So the fix was to add the missing warning.  Then the warnings I got from my code doesn't apply to this fix.  Ok, here's what happened in my case.  I have a small class that is like this below.

<?
class myClass{
	public $drives = array();
	
	public function get_drives(){
		$sql = 'CALL some_stored_procedure()'; 
		$result = mysql_query($sql);
		if(mysql_num_rows($result)){
			while($row = mysql_fetch_array($result)){
				$this->drives[] = $row['drive_id'];
			}
		}
	}
}
?>

Line "$this->drives[] = $row['drive_id'];" throws out the same warning.  I'm scracthing my head trying to resolve this.  Any ideas?
 [2008-11-15 15:26 UTC] lbarnaud@php.net
Does this code really adds an element with key 0x80000000 and then an other with 0x7FFFFFFF ?
There is many possible work arounds for this issue. The simplest one is probably to do $this->drives[$row['drive_id']] = $row['drive_id'].

 [2008-11-16 01:15 UTC] jian at theorchard dot com
I'm not sure if this code really adds an element with key 0x80000000 and then an other with 0x7FFFFFFF?  It's very hard to reproduce it.  It only has happened twice.  Your suggestion should fix the problem.  But I was so surprised that I got that warning.
 [2008-12-09 12:52 UTC] jani@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


 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of rquadling
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=69ae2850dfab59f1f2fc5520f620238b22fc75b7
Log: css =&gt; cssversion. Fix #46561
 [2020-02-07 06:10 UTC] phpdocbot@php.net
-Status: Not a bug +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC