ID:               49068
 User updated by:  simon+php at thulbourn dot com
 Reported By:      simon+php at thulbourn dot com
 Status:           Bogus
 Bug Type:         Scripting Engine problem
 Operating System: *
 PHP Version:      5.*, 6SVN (2009-07-26)
 New Comment:

I believe that it should issue a warning rather than converting to an 
integer.

It seems like a retarded action to convert the string to a 0, if I was

to use a numeric index that doesn't exist, I'd receive a notice. Some 
consistency would be nice.


Previous Comments:
------------------------------------------------------------------------

[2009-07-26 23:07:46] ras...@php.net

That has nothing to do with a foreach.  The same effect can be seen
with:

$a = 'foo';
echo $a['bar'];

$a is a string which is essentially an array of characters with
numerical indices.  Given that, 'bar' is converted to an integer, so you
end up with $a[0] which does exist, so no warning.

------------------------------------------------------------------------

[2009-07-26 22:09:07] simon+php at thulbourn dot com

Description:
------------
An array with no associative keys doesn't throw a notice or error when

one is used as an associative keyed array.

Reproduce code:
---------------
<?php

        $array = array('foo', 'bar', 'baz');
        
        foreach ($array as $a) {
                echo $a['foo'];
        }

?>

Expected result:
----------------
Notice: Undefined index

Actual result:
--------------
fbb


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=49068&edit=1

Reply via email to