Skip to content

JIT: Integer string in variable used as offset produces wrong undefined array key warning #12812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Girgias opened this issue Nov 28, 2023 · 1 comment

Comments

@Girgias
Copy link
Member

Girgias commented Nov 28, 2023

Description

Found while working on #12723

The following code:

<?php

$container = [];
$dimension = '7';

try {
    var_dump($container['7']);
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($container[$dimension]);
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}

Resulted in this output:

Warning: Undefined array key 7 in %s on line %d
NULL

Warning: Undefined array key "7" in %s on line %d
NULL

But I expected this output instead:

Warning: Undefined array key 7 in %s on line %d
NULL

Warning: Undefined array key 7 in %s on line %d
NULL

PHP Version

PHP 8.2

Operating System

No response

@Girgias
Copy link
Member Author

Girgias commented Nov 28, 2023

@dstogov Can you have a look at this? I have no idea why this doesn't work as expected as the relevant JIT handler (zend_jit_fetch_dim_r_helper()) looks to be implemented correctly. Here is the test file:

--TEST--
GH-12812: JIT: Integer string in variable used as offset produces wrong undefined array key warning
--INI--
opcache.enable=1
opcache.enable_cli=1
--FILE--
<?php

$container = [];
$dimension = '7';

try {
    var_dump($container['7']);
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}
try {
    var_dump($container[$dimension]);
} catch (\Throwable $e) {
    echo $e->getMessage(), "\n";
}

?>
--EXPECTF--
Warning: Undefined array key 7 in %s on line %d
NULL

Warning: Undefined array key 7 in %s on line %d
NULL

dstogov added a commit to dstogov/php-src that referenced this issue Nov 28, 2023
dstogov added a commit to dstogov/php-src that referenced this issue Nov 28, 2023
* PHP-8.2:
  Fixed phpGH-12812: Integer string in variable used as offset produces wrong undefined array key warning (php#12817)
dstogov added a commit to dstogov/php-src that referenced this issue Nov 28, 2023
* PHP-8.3:
  Fixed phpGH-12812: Integer string in variable used as offset produces wrong undefined array key warning (php#12817)
dstogov added a commit that referenced this issue Nov 28, 2023
* PHP-8.3:
  Fixed GH-12812: Integer string in variable used as offset produces wrong undefined array key warning (#12817)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant