Bug #72234 [NEW]: Calling foreach on non-array is ignored
From: nickdnk at hotmail dot com
Operating system: Windows
PHP version: 7.0.6
Package: *General Issues
Bug Type: Bug
Bug description:Calling foreach on non-array is ignored
Description:
------------
Hello
If passing a variable (let's say a stdClass) to the foreach method, it
does not produce an error. It silently does not loop the object (since
it cannot).
I'm no expert, but I'd say that at least a warning should be raised if
trying to iterate a non-array object. I'm sorry if this is intentional,
but I do believe an error was raised in 5.6.
Test script:
---------------
$obj = new stdClass();
foreach ($obj as $anObj) {
error_log("nothing is output here, obviously, but no error
either");
}
Expected result:
----------------
I expect an error or warning to occur, since I'm traversing a non-array.
Actual result:
--------------
Nothing happens at all.
--
Edit bug report at https://bugs.php.net/bug.php?id=72234&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72234&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72234&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72234&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72234&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72234&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72234&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72234&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72234&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72234&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72234&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72234&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72234&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72234&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72234&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72234&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72234&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72234&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72234&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72234&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72234&r=mysqlcfg
Thread (3 messages)
- nickdnk at hotmail dot com