mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Fix GMP comparison object handler
gmp_cmp() doesn't return false anymore in PHP 8 but will throw an Error if compared to a non numeric string or another type of object. Closes GH-6553
This commit is contained in:
parent
af7445b9ac
commit
1b5c62facd
2 changed files with 29 additions and 1 deletions
|
@ -429,9 +429,14 @@ static int gmp_compare(zval *op1, zval *op2) /* {{{ */
|
|||
zval result;
|
||||
|
||||
gmp_cmp(&result, op1, op2);
|
||||
if (Z_TYPE(result) == IS_FALSE) {
|
||||
|
||||
/* An error/exception occurs if one of the operands is not a numeric string
|
||||
* or an object which is different from GMP */
|
||||
if (EG(exception)) {
|
||||
return 1;
|
||||
}
|
||||
/* result can only be a zend_long if gmp_cmp hasn't thrown an Error */
|
||||
ZEND_ASSERT(Z_TYPE(result) == IS_LONG);
|
||||
return Z_LVAL(result);
|
||||
}
|
||||
/* }}} */
|
||||
|
|
23
ext/gmp/tests/comparison_invalid.phpt
Normal file
23
ext/gmp/tests/comparison_invalid.phpt
Normal file
|
@ -0,0 +1,23 @@
|
|||
--TEST--
|
||||
Invalid comparison with a GMP object
|
||||
--SKIPIF--
|
||||
<?php if (!extension_loaded("gmp")) print "skip"; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
try {
|
||||
var_dump("hapfegfbu" > gmp_init(0));
|
||||
} catch (\Error $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
var_dump((new DateTime()) > gmp_init(0));
|
||||
} catch (\Error $e) {
|
||||
echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
|
||||
}
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
TypeError: main(): Argument #2 is not an integer string
|
||||
TypeError: main(): Argument #2 must be of type GMP|string|int, DateTime given
|
Loading…
Add table
Add a link
Reference in a new issue