Bug #80404 [NEW]: opcache breaks expression evaluation order when cast as int

From: Date: Mon, 23 Nov 2020 10:06:00 +0000
Subject: Bug #80404 [NEW]: opcache breaks expression evaluation order when cast as int
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230533@lists.php.net to get a copy of this message
From:             contact at shivammathur dot com
Operating system: Tested on Ubuntu 18.04
PHP version:      8.0Git-2020-11-23 (Git)
Package:          Math related
Bug Type:         Bug
Bug description:opcache breaks expression evaluation order when cast as int

Description:
------------
PHP 8.0.0-dev (cli) (built: Nov 23 2020 00:27:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.0-dev, Copyright (c), by Zend Technologies

Build Configuration:
https://github.com/shivammathur/php-builder/blob/master/.github/scripts/8.0

Script: https://3v4l.org/kkRIE
  curl -o test.php -H Accept:text/plain -sL https://3v4l.org/kkRIE
  for ((i=1;i<=5;i++)); 
  do 
     echo $i
     php test.php
     sleep 1
  done

Above snippet will run the script "https://3v4l.org/kkRIE" multiple
times and when opcache kicks in "(int) (63/ 120 * 100)" starts
evaluating to 0.

This works fine with opcache disabled on PHP 8.0 and with or without
opcache on PHP 7.4

Test workflow -
https://github.com/shivammathur/test-setup-php/runs/1441325553?check_suite_focus=true#step:6:33



Test script:
---------------
<?php

$firstRowColumns  = 63;

var_dump([
    $firstRowColumns,
    ($firstRowColumns / 120),
    ($firstRowColumns / 120 * 100),
    (int) ($firstRowColumns / 120 * 100),
]);

Expected result:
----------------
(int) (63/ 120 * 100) should evaluate to 52 with opcache enabled on PHP
8.0

Actual result:
--------------
(int) (63/ 120 * 100) evaluates to 0 with opcache enabled on PHP 8.0

-- 
Edit bug report at https://bugs.php.net/bug.php?id=80404&edit=1
-- 
Fix committed:                    https://bugs.php.net/fix.php?id=80404&r=fixed
Fixed in release:                 https://bugs.php.net/fix.php?id=80404&r=alreadyfixed
Need backtrace:                   https://bugs.php.net/fix.php?id=80404&r=needtrace
Need Reproduce Script:            https://bugs.php.net/fix.php?id=80404&r=needscript
Try newer version:                https://bugs.php.net/fix.php?id=80404&r=oldversion
Not developer issue:              https://bugs.php.net/fix.php?id=80404&r=support
Expected behavior:                https://bugs.php.net/fix.php?id=80404&r=notwrong
Not enough info:                  https://bugs.php.net/fix.php?id=80404&r=notenoughinfo
Submitted twice:                  https://bugs.php.net/fix.php?id=80404&r=submittedtwice
register_globals:                 https://bugs.php.net/fix.php?id=80404&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80404&r=phptooold
Daylight Savings:                 https://bugs.php.net/fix.php?id=80404&r=dst
IIS Stability:                    https://bugs.php.net/fix.php?id=80404&r=isapi
Install GNU Sed:                  https://bugs.php.net/fix.php?id=80404&r=gnused
Floating point limitations:       https://bugs.php.net/fix.php?id=80404&r=float
No Zend Extensions:               https://bugs.php.net/fix.php?id=80404&r=nozend
MySQL Configuration Error:        https://bugs.php.net/fix.php?id=80404&r=mysqlcfg


Thread (6 messages)

« previous php.bugs (#230533) next »