Skip to content

Bug with JIT / Opcache on float / int calculation #21949

@ahfeel

Description

@ahfeel

Description

The following code:

<?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

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

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

PHP Version

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions