mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
RFC: Change GMP bool cast behavior (#15151)
Implementation of "RFC: Change GMP bool cast behavior" https://wiki.php.net/rfc/fix_up_bcmath_number_class Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
This commit is contained in:
2
NEWS
2
NEWS
@@ -2,6 +2,8 @@ PHP NEWS
|
|||||||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||
?? ??? ????, PHP 8.4.0beta1
|
?? ??? ????, PHP 8.4.0beta1
|
||||||
|
|
||||||
|
- GMP:
|
||||||
|
. RFC: Change GMP bool cast behavior. (Saki Takamachi)
|
||||||
|
|
||||||
01 Aug 2024, PHP 8.4.0alpha3
|
01 Aug 2024, PHP 8.4.0alpha3
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ PHP 8.4 UPGRADE NOTES
|
|||||||
- GMP:
|
- GMP:
|
||||||
. The GMP class is now final and cannot be extended anymore.
|
. The GMP class is now final and cannot be extended anymore.
|
||||||
RFC: https://wiki.php.net/rfc/gmp-final
|
RFC: https://wiki.php.net/rfc/gmp-final
|
||||||
|
. Casting a GMP object to bool changed so that 0 becomes false and everything else
|
||||||
|
becomes true.
|
||||||
|
RFC: https://wiki.php.net/rfc/fix_up_bcmath_number_class
|
||||||
|
|
||||||
- Intl:
|
- Intl:
|
||||||
. resourcebundle_get(), ResourceBundle::get(), and accessing offsets on a
|
. resourcebundle_get(), ResourceBundle::get(), and accessing offsets on a
|
||||||
|
|||||||
@@ -298,6 +298,10 @@ static zend_result gmp_cast_object(zend_object *readobj, zval *writeobj, int typ
|
|||||||
ZVAL_DOUBLE(writeobj, mpz_get_d(gmpnum));
|
ZVAL_DOUBLE(writeobj, mpz_get_d(gmpnum));
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
case _IS_BOOL:
|
||||||
|
gmpnum = GET_GMP_OBJECT_FROM_OBJ(readobj)->num;
|
||||||
|
ZVAL_BOOL(writeobj, mpz_sgn(gmpnum) != 0);
|
||||||
|
return SUCCESS;
|
||||||
default:
|
default:
|
||||||
return FAILURE;
|
return FAILURE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,25 @@ var_dump((int) $n);
|
|||||||
var_dump((float) $n);
|
var_dump((float) $n);
|
||||||
var_dump((bool) $n);
|
var_dump((bool) $n);
|
||||||
|
|
||||||
|
echo "\n";
|
||||||
|
|
||||||
|
$zero = gmp_init(0);
|
||||||
|
echo $zero, "\n";
|
||||||
|
var_dump((string) $zero);
|
||||||
|
var_dump((int) $zero);
|
||||||
|
var_dump((float) $zero);
|
||||||
|
var_dump((bool) $zero);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECT--
|
||||||
42
|
42
|
||||||
string(2) "42"
|
string(2) "42"
|
||||||
int(42)
|
int(42)
|
||||||
float(42)
|
float(42)
|
||||||
|
bool(true)
|
||||||
|
|
||||||
Recoverable fatal error: Object of class GMP could not be converted to bool in %s on line %d
|
0
|
||||||
|
string(1) "0"
|
||||||
|
int(0)
|
||||||
|
float(0)
|
||||||
|
bool(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user