[php-src] Issue #21949: Bug with JIT / Opcache on float / int calculation

[email protected] (ahfeel)
Newsgroups php.bugs
Message-ID <[email protected]>
Issue: https://github.com/php/php-src/issues/21949
Author: ahfeel

### Description

The following code:

```php
<?php

function calculateHealthScore(float $p, int $s): int
{
    if ($p === 0.0) {
        return 0;
    }

    $partnerIncreasedSales = $s * 1.5;

    if ($p + $partnerIncreasedSales < 0) {
        return (int) round(($partnerIncreasedSales / abs($p)) * 100);
    }

    return 100;
}

$x = unserialize(file_get_contents('vars.txt'));

foreach ($x as $affiliateId => $affiliateStats) {
    $x[$affiliateId]['health'] = calculateHealthScore(
        $x[$affiliateId]['profitability'],
        $x[$affiliateId]['sales_nb']
    );
}

var_dump($x[2376086]);
```

Resulted in this output *ON THE FIRST RUN*:
```
array(4) {
  ["sales_nb"]=>
  string(1) "7"
  ["affiliate"]=>
  int(2376086)
  ["profitability"]=>
  string(6) "-13.45"
  ["health"]=>
  int(78)
}
```

Then resulted in this output *ON THE SECOND RUN*
```
Resulted in this output *ON THE FIRST RUN*:
```
array(4) {
  ["sales_nb"]=>
  string(1) "7"
  ["affiliate"]=>
  int(2376086)
  ["profitability"]=>
  string(6) "-13.45"
  ["health"]=>
  int(0)
}
```

But I expected this output instead:
```
array(4) {
  ["sales_nb"]=>
  string(1) "7"
  ["affiliate"]=>
  int(2376086)
  ["profitability"]=>
  string(6) "-13.45"
  ["health"]=>
  int(78)
}
```

When running again with the -d opcache.jit=0 option:
```
array(4) {
  ["sales_nb"]=>
  string(1) "7"
  ["affiliate"]=>
  int(2376086)
  ["profitability"]=>
  string(6) "-13.45"
  ["health"]=>
  int(78)
}
```

[vars.txt](https://github.com/user-attachments/files/27376969/vars.txt)

Changing the $p parameter from float to string fixes the issue :-/

### PHP Version

```plain
PHP 8.5.5 (cli) (built: Apr  9 2026 22:14:19) (NTS)
Copyright (c) The PHP Group
Built by https://github.com/docker-library/php
Zend Engine v4.5.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.5.5, Copyright (c), by Zend Technologies
```

### Operating System

Tested on Ubuntu, Debian and PHP in Docker
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.