[php-src] Issue #7880: json_decode() native arguments like JSON_OBJECT_AS_ARRAY have the wrong type when using strict type
| From: | tschallacka | Date: | Tue, 04 Jan 2022 10:26:18 +0000 |
| Subject: | [php-src] Issue #7880: json_decode() native arguments like JSON_OBJECT_AS_ARRAY have the wrong type when using strict type | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-238748@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7880
Author: tschallacka
### Description
The following code:
```php
<?php
declare(strict_types=1);
$test =
'[{"foo":"bar"},{"foo":"baz"},{"foo":"bal"}]';
$data = json_decode($test, JSON_OBJECT_AS_ARRAY);
var_dump($data);
```
Resulted in this output:
```
PHP Fatal error: Uncaught TypeError: json_decode(): Argument #2 ($associative) must be of type
?bool, int given in /home/mdibbets/git/dugros-integrations/var/data/test/strict.php:4
Stack trace:
#0 /home/mdibbets/git/dugros-integrations/var/data/test/strict.php(4): json_decode()
#1 {main}
thrown in /home/mdibbets/git/dugros-integrations/var/data/test/strict.php on line 4
```
But I expected this output instead:
```
array(3) {
[0]=>
array(1) {
["foo"]=>
string(3) "bar"
}
[1]=>
array(1) {
["foo"]=>
string(3) "baz"
}
[2]=>
array(1) {
["foo"]=>
string(3) "bal"
}
}
```
### PHP Version
8.0
### Operating System
Ubuntu 20.04