Skip to content

Failed to invoke user error handler during index conversion in JIT #16396

Closed as not planned

Description

@YuanchengJiang

Description

The following code:

<?php
class C {
    public function __construct(
        $prop { set => $value * 2; }
    ) {}
}
$c = new C(42);
$fusion = $c;
set_error_handler(function($code, $msg) {
    echo "Err: $msg\n";
    $GLOBALS[''] = $GLOBALS['y'];
});
function x(&$s){
    $fusion[100000000000000000000] = 1;
}
x($y);
var_dump($y);
?>

Resulted in this output:

NULL

But I expected this output instead:

Err: Implicit conversion from float 1.0E+20 to int loses precision
NULL

To reproduce:

-d "opcache.enable=1" -d "opcache.enable_cli=1"

PHP Version

nightly

Operating System

ubuntu 22.04

Activity

  1. cmb69 commented on Oct 12, 2024

    @cmb69
    Member

    This is not related to JIT, but rather to the optimizer. Consider:

    function x(&$s){
        $fusion[100000000000000000000] = 1;
    }

    The optimizer determines that the assignment to $fusion is irrelevant for the rest of the program, and so completely optimizes the assignment away, and as such there is no E_DEPRECATED.

    OPcode dump
    x:
         ; (lines=4, args=1, vars=2, tmps=1)
         ; (before optimizer)
         ; C:\php-sdk\phpdev\vs17\x64\gh16396.php:2-4
         ; return  [] RANGE[0..0]
    0000 CV0($s) = RECV 1
    0001 ASSIGN_DIM CV1($fusion) float(1e+20)
    0002 OP_DATA int(1)
    0003 RETURN null
    
    x:
         ; (lines=2, args=1, vars=1, tmps=0)
         ; (after optimizer)
         ; C:\php-sdk\phpdev\vs17\x64\gh16396.php:2-4
    0000 CV0($s) = RECV 1
    0001 RETURN null
    

    It would be different for

    function x(&$s, $offset){
        $fusion[$offset] = 1;
    }
    x($y, 100000000000000000000);

    or

    $fusion[100000000000000000000] = 1;

    where you get the warning.

  2. cmb69 commented on Oct 12, 2024

    @cmb69
    Member

    Oh, forgot: you can completely disable the optimizer if desired: -d opcache.optimization_level=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions