From:             php at bucksvsbytes dot com
Operating system: Ubuntu
PHP version:      5.2.4
PHP Bug Type:     Scripting Engine problem
Bug description:  undesirable invalid argument in foreach

Description:
------------
In PHP4, foreach($array) runs without error if $array is an uninitialized
array. The foreach block is executed 0 times. This is consistent with other
0 iteration blocks such as while(false) and for($i=0;$i<0). In PHP5, an
inconsistency was introduced by throwing an "invalid argument" warning when
$array is an uninitialized array. In upgrading to PHP5 I had to add a
surrounding if($array) block to hundreds of foreach blocks to eliminate the
possible warning message.

Reproduce code:
---------------
unset($array);//just to clarify initial conditions
foreach($array['phone'] as $key=>$phone){
 echo $phone.'<br/>';
}

Expected result:
----------------
I expect no errors and nothing echoed. This is PHP4 behavior.

Actual result:
--------------
In PHP5, following message pointlessly prints:
Warning: Invalid argument supplied for foreach() in ...

-- 
Edit bug report at http://bugs.php.net/?id=43072&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43072&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43072&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43072&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43072&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43072&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43072&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43072&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43072&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43072&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43072&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43072&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43072&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43072&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43072&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43072&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43072&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43072&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43072&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43072&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43072&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43072&r=mysqlcfg

Reply via email to