Bug #80309 [NEW]: numerical array keys converted to int in strict mode

From: Date: Mon, 02 Nov 2020 22:49:41 +0000
Subject: Bug #80309 [NEW]: numerical array keys converted to int in strict mode
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230070@lists.php.net to get a copy of this message
From:             shop1 at mokraemer dot de
Operating system: Linux
PHP version:      Irrelevant
Package:          Arrays related
Bug Type:         Bug
Bug description:numerical array keys converted to int in strict mode

Description:
------------
numerical array keys are converted to integers.
In strict mode (typed properties, typed function parameters), this is
not desireable.

Test script:
---------------
declare(strict_types=1);
function f(string $s):string{
	return $s;
}

$array=[
	'x'=>5,
	'1'=>6
];

foreach($array as $k => $v){
	echo f($k);
}


Expected result:
----------------
x1

Actual result:
--------------
xPHP Fatal error:  Uncaught TypeError: Argument 1 passed to f() must be
of the type string, int given, called in /tmp/test.php on line 13 and
defined in /tmp/test.php:3
Stack trace:
#0 /tmp/test.php(13): f()
#1 {main}
  thrown in /tmp/test.php on line 3


-- 
Edit bug report at https://bugs.php.net/bug.php?id=80309&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80309&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80309&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80309&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80309&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80309&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80309&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80309&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80309&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80309&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80309&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80309&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80309&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80309&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80309&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80309&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80309&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80309&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#230070) next »