Bug #68002 [Opn->Wfx]: GMP throwing warnings for invalid numbers

From: Date: Sat, 26 Mar 2016 11:30:54 +0000
Subject: Bug #68002 [Opn->Wfx]: GMP throwing warnings for invalid numbers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200108@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68002&edit=1

 ID:                 68002
 Updated by:         nikic@php.net
 Reported by:        Rican7 at gmail dot com
 Summary:            GMP throwing warnings for invalid numbers
-Status:             Open
+Status:             Wont fix
 Type:               Bug
 Package:            GNU MP related
 Operating System:   CentOS
 PHP Version:        5.6.0
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2014-09-10 19:01:47] Rican7 at gmail dot com

Description:
------------
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)"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68002&edit=1


Thread (2 messages)

« previous php.bugs (#200108) next »