|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68002 GMP throwing warnings for invalid numbers
Submitted: 2014-09-10 19:01 UTC Modified: 2016-03-26 11:30 UTC
Avg. Score:2.5 ± 1.7
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: Rican7 at gmail dot com Assigned:
Status: Wont fix Package: GNU MP related
PHP Version: 5.6.0 OS: CentOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: Rican7 at gmail dot com
New email:
PHP Version: OS:


 [2014-09-10 19:01 UTC] Rican7 at gmail dot com
Prior to PHP 5.6, you could pass a non-numeric string to `gmp_init()` and it would simply return false, allowing you to handle any bad input errors yourself with a boolean check.

Since the changes to GMP in PHP 5.6, `gmp_init()` will throw an uncatchable warning: "Unable to convert variable to GMP - string is not an integer".

Now, when writing libraries that use GMP, the library has to duplicate the internal validations to avoid throwing an error.

This would be ok if there was some sort of public API for the GMP validation, but there isn't.

Test script:
$gmp = gmp_init('doge'); // Throws warning on 5.6

Expected result:
$gmp = gmp_init('doge');
var_dump($gmp); // yields "bool(false)"

Actual result:
$gmp = gmp_init('doge'); // Throws warning
var_dump($gmp); // yields "bool(false)"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-26 11:30 UTC]
-Status: Open +Status: Wont fix
 [2016-03-26 11:30 UTC]
There's a tradeoff involved here, between ease of detecting mistakes in normal code (where nobody does, and nobody should, check the return value of gmp_init) and ease of handling failures in libraries. A choice has been made and I don't think this is going to change back. You have the option of either manually validating input, using error suppression or elevating the warning to an exception.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Apr 11 23:01:23 2021 UTC