php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8622 Using "0" as a key in accociative arrays crashes reset() , next(), etc.
Submitted: 2001-01-09 19:05 UTC Modified: 2001-01-10 07:17 UTC
From: sooprock at aol dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4 OS: Linux (also NT)
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: sooprock at aol dot com
New email:
PHP Version: OS:

 

 [2001-01-09 19:05 UTC] sooprock at aol dot com
<?
  print "Using \"0\" as a key in accociative arrays<br>\n"
       ."crashes reset() , next(), etc.<br><br>\n\n";

  $groupid["SHOOT"] = "DARNIT";
  $groupid["DER"] = "DARNIT";
  $groupid["FSD"] = "DARNIT";
  $groupid["SDF"] = "DARNIT";
  $groupid["DSF"] = "DARNIT";
  $groupid["0"] = "DARNIT";
  $groupid["DSF2"] = "DARNIT";

  print "REGULAR VARIABLE REFERENCING WORKS:<br>\n";
  print "\$groupid[\"SHOOT\"] = ".$groupid["SHOOT"]."<br>\n";
  print "\$groupid[\"DER\"] = ".$groupid["DER"]."<br>\n";
  print "\$groupid[\"FSD\"] = ".$groupid["FSD"]."<br>\n";
  print "\$groupid[\"0\"] = ".$groupid["0"]."<br>\n";
  print "\$groupid[\"SDF\"] = ".$groupid["SDF"]."<br>\n";
  print "\$groupid[\"DSF\"] = ".$groupid["DSF"]."<br>\n";
  print "\$groupid[\"DSF2\"] = "
       .$groupid["DSF2"]."<br><br>\n";

print "arraycount = ".count($groupid)."<BR>\n";
print "Using 'for (reset(\$groupid); \$key = key(\$groupid); next(\$groupid))'<BR>\n";
for (reset($groupid); $key = key($groupid); next($groupid)) {
   print "\$groupid[\"$key\"] = $groupid[$key]<br>\n";
}
print "<br>\nThe arraycount still works and so does<br>\n"
     ."referencing the variable, however, the reset()<br>\n"
     ."next(), and associated functions crash.<br>\n";
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-10 07:17 UTC] cynic@php.net
IIRC this is described in the manual. use 

while( list( $key , ) = each( $groupid ) ) {
    ...
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Sep 27 00:01:27 2024 UTC