[php-src] Issue #9029: Array numeric string key gets converted to int
| From: | piku235 | Date: | Sat, 16 Jul 2022 15:50:07 +0000 |
| Subject: | [php-src] Issue #9029: Array numeric string key gets converted to int | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-241940@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9029
Author: piku235
### Description
I ran into this bug while playing with query params. My script had
declare(strict_types=1) and was iterating keys from $_GET using a function
with the typed argument string ...$keys, but surprisingly for GET
/script.php?123=foo my script ended with a fatal error stating that argument to that function
must be of type string but got int.
At first, I thought it was a framework bug, but as I delved deeper and deeper, it finally led me to
arrays. When I passed a numeric string key such as "123" it got converted to int, where I
expected it to remain as a string.
The below code:
```php
<?php
$arr = array('123' => 'foo');
var_dump(array_keys($arr));
```
Resulted in this output:
```
array(1) {
[0]=>
int(123)
}
```
But I expected this output instead:
```
array(1) {
[0]=>
string(3) "123"
}
```
It looks like this bug exists for a very long time, also tested on PHP 7.0 and the result was the
same.
### PHP Version
8.2.0-dev
### Operating System
_No response_