[PHP-BUG] Bug #74327 [NEW]: foreach: wrong typecasting breaks strict mode

[email protected] ("spam2 at rhsoft dot net")
Newsgroups php.bugs
Message-ID <[email protected]>
From:             spam2 at rhsoft dot net
Operating system: 
PHP version:      7.1.3
Package:          Arrays related
Bug Type:         Bug
Bug description:foreach: wrong typecasting breaks strict mode

Description:
------------
[harry@rh:/downloads]$ php test.php
Fatal error: Uncaught TypeError: Argument 1 passed to test() must be of
the type string, integer given, called in /mnt/data/downloads/test.php
on line 11 and defined in /mnt/data/downloads/test.php:13
Stack trace:
#0 /mnt/data/downloads/test.php(11): test(1, 'c')
#1 {main}
  thrown in /mnt/data/downloads/test.php on line 13
____________________________________

why in the world is the array-key silently cased to an integer - if that
would have been the intention the code would be 1=>'c' instead '1'=>'c'

besides that this breaks strict mode that conversion are useless
cpy-cycles

Test script:
---------------
[harry@rh:/downloads]$ cat test.php
<?php declare(strict_types=1);
$arr =
[
 'a' => 'a',
 'b' => 'b',
 '1' => 'c',
 '2' => 'd'
];
foreach($arr as $key=>$value)
{
 test($key, $value);
}
function test(string $a, string $b)
{

}


-- 
Edit bug report at https://bugs.php.net/bug.php?id=74327&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74327&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74327&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74327&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74327&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74327&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74327&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74327&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74327&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74327&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74327&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74327&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74327&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74327&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74327&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74327&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74327&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74327&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74327&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74327&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74327&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.