[php-src] Issue #11026: `array_push($arr, $map)` should support non-numeric keys
| From: | mvorisek | Date: | Thu, 06 Apr 2023 20:57:51 +0000 |
| Subject: | [php-src] Issue #11026: `array_push($arr, $map)` should support non-numeric keys | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244130@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11026
Author: mvorisek
### Description
The following code:
https://3v4l.org/0p5Sv
```php
<?php
function array_push_cust(&$arr, ...$args) {
foreach ($args as $k => $v) {
if (is_int($k)) {
$arr[] = $v;
} else {
$arr[$k] = $v;
}
}
}
$arr = [1, 'a' => 2];
$arr2 = [3, 'b' => 4];
$res = $arr;
array_push_cust($res, ...$arr2);
print_r($res);
$res = $arr;
array_push($res, ...$arr2);
print_r($res);
```
Resulted in this output:
```
Array
(
[0] => 1
[a] => 2
[1] => 3
[b] => 4
)
Fatal error: Uncaught ArgumentCountError: array_push() does not accept unknown named parameters in
/in/0p5Sv:21
Stack trace:
#0 /in/0p5Sv(21): array_push(Array, 3, b: 4)
#1 {main}
thrown in /in/0p5Sv on line 21
```
But I expected this output instead:
```
Array
(
[0] => 1
[a] => 2
[1] => 3
[b] => 4
)
Array
(
[0] => 1
[a] => 2
[1] => 3
[b] => 4
)
```
### PHP Version
*
### Operating System
*