|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32670 foreach sets source variable if not already set and does not issue warning
Submitted: 2005-04-11 16:07 UTC Modified: 2005-05-03 03:30 UTC
From: cmoore at iyd dot com Assigned:
Status: Closed Package: Arrays related
PHP Version: 4CVS, 5CVS (2005-04-11) OS: *
Private report: No CVE-ID:
 [2005-04-11 16:07 UTC] cmoore at iyd dot com
prior versions of php (4.3.10 tested) will issue a warning if an unset variable is passed to foreach(). even with error_reporting(E_ALL), this one will not warn. the warning would be nice to see with the same level of error reporting that if() warns at.

Reproduce code:
foreach($check as $test)

Expected result:
Warning: Invalid argument supplied for foreach() in test.php on line 3

Actual result:
there is no result in 4.3.11


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-11 17:36 UTC]
Result with PHP 4 CVS: nothing
Result with PHP 5 CVS:

Notice: Undefined variable: check in /home/jani/t.php on line 3

Warning: Invalid argument supplied for foreach() in /home/jani/t.php on line 3
/usr/src/php/php5/Zend/zend_vm_execute.h(18237) :  Freeing 0x0968A434 (16 bytes), script=t.php
=== Total 1 memory leaks detected ===

 [2005-05-03 03:30 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Tue Nov 24 22:01:36 2015 UTC