php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #1371 handling of each() over empty lists
Submitted: 1999-05-02 21:22 UTC Modified: 1999-06-12 16:45 UTC
From: nathanh at chirp dot com dot au Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 3.0.7 OS: Linux
Private report: No CVE-ID: None
 [1999-05-02 21:22 UTC] nathanh at chirp dot com dot au
The following code snippet generates a nasty warning when $mylist is empty.

  while (list($key, $val) = each($mylist)) { 
    // do warning
  }

The workaround in PHP is trivial, but ugly.

  while (count($mylist) and list($key, $val) = each($mylist)) { 
    // do warning
  }

Would be nicer if the each() iterator just returned nothing, causing the while loop to terminate, when the list is empty.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-12 16:45 UTC] jim at cvs dot php dot net
Simple prefix each() with an at-sign (@) to suppress the warning.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 14 10:00:01 2026 UTC