[php-src] Issue #12927: Narrowing occurred during type inference of ZEND_FETCH_DIM_RW

From: Date: Mon, 11 Dec 2023 07:02:32 +0000
Subject: [php-src] Issue #12927: Narrowing occurred during type inference of ZEND_FETCH_DIM_RW
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-246028@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/12927
Author: mns-tftc

### Description

The following code:

```php
<?php
public static function get_brand_by_orders(array $orders): array
{
    $count_by_brand = [];
    foreach ($orders as $order) {
        if (isset($count_by_brand[$order->get_brand()])) {
            $count_by_brand[$order->get_game()]->qty++; // this is the line where script fail
Contract.php:588
        } else {
            $obj = new stdClass();
            $obj->brand = $order->get_brand();
            $obj->count = 1;
    
            $count_by_brand[$order->get_brand()] = $obj;
        }
    }
    
    return $count_by_brand;
```

Resulted in this output:
```
"message": "Call of
Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError() throws uncaught
ErrorException: \"Narrowing occurred during type inference of ZEND_FETCH_DIM_RW. Please file a
bug report on https://github.com/php/php-src/issues\"
in /var/www/deployhq/hellcase/releases/20231211063950/app/Models/Contract/Contract.php:588",
    "exception": "ErrorException",
```

But I expected this output instead:
```
```


### PHP Version

PHP 8.2.13

### Operating System

Ubuntu 20.04


Thread (1 message)

  • mns-tftc
« previous php.bugs (#246028) next »