Bug #81119 [NEW]: GMP operators throw errors with wrong parameter names
From: lauri dot kentta+php-bugs at gmail dot com
Operating system:
PHP version: master-Git-2021-06-09 (Git)
Package: GNU MP related
Bug Type: Bug
Bug description:GMP operators throw errors with wrong parameter names
Description:
------------
When using GMP class operators such as + or < with an invalid second
value (such as non-numeric string or array), the exception picks up
parameter name from the outer scope. Operator parameter probably doesn't
have any meaningful name. The bad messages come from ext/gmp/gmp.c,
function convert_to_gmp, lines 623 and 632.
Just run (gmp_init(1) < "x") inside a function, and you'll find the
second function parameter name in the error message.
Test script:
---------------
<?php
function test($f) {
try {
$f();
echo "No error?\n";
} catch (TypeError|ValueError $e) {
if (strpos($e->getMessage(), '($WRONG_SCOPE_')) {
echo "Bad error! ", $e->getMessage(), "\n";
} else {
echo "Good error.\n";
}
}
}
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) < "x");
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) < []);
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) + "x");
test(fn($WRONG_SCOPE_1 = 0, $WRONG_SCOPE_2 = 0) => gmp_init(1) + []);
Expected result:
----------------
Good error.
Good error.
Good error.
Good error.
Actual result:
--------------
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) is not an integer
string
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) must be of type
GMP|string|int, array given
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) is not an integer
string
Bad error! {closure}(): Argument #2 ($WRONG_SCOPE_2) must be of type
GMP|string|int, array given
--
Edit bug report at https://bugs.php.net/bug.php?id=81119&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=81119&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=81119&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=81119&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=81119&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=81119&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=81119&r=support
Expected behavior: https://bugs.php.net/fix.php?id=81119&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=81119&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=81119&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=81119&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=81119&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=81119&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=81119&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=81119&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=81119&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=81119&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=81119&r=mysqlcfg
Thread (3 messages)
- lauri dot kentta+php-bugs at gmail dot com