From: postings-php-bug at hans-spath dot de
Operating system: Linux 2.6.22
PHP version: 5.2.9
PHP Bug Type: GNU MP related
Bug description: gmp_fact() parameter type not checked + documentation problem
Description:
------------
If you pass a GMP resource as parameter to gmp_fact(), it calculates and
returns the factorial of the internal resource number, not of the GMP value
in the resource.
In the PHP manual the function prototype is given as:
"resource gmp_fact ( int $a )"
However, in the parameter description it says:
"It can be either a GMP number resource,
or a numeric string given that it is possible
to convert the latter to a number."
This is misleading.
Furthermore gmp_fact should check the parameter type and either accept GMP
resources or throw a warning.
Reproduce code:
---------------
<?php
for ($i = 0; $i < 3; $i++) {
$nine = gmp_init('9');
var_dump($nine);
echo '9! = ', gmp_strval(gmp_fact($nine)), "\n";
}
Expected result:
----------------
resource(4) of type (GMP integer)
9! = 362880
resource(6) of type (GMP integer)
9! = 362880
resource(8) of type (GMP integer)
9! = 362880
*** or ***
resource(4) of type (GMP integer)
9! =
Warning: gmp_fact(): parameter must be int
resource(6) of type (GMP integer)
9! =
Warning: gmp_fact(): parameter must be int
resource(8) of type (GMP integer)
9! =
Warning: gmp_fact(): parameter must be int
Actual result:
--------------
resource(4) of type (GMP integer)
9! = 24
resource(6) of type (GMP integer)
9! = 720
resource(8) of type (GMP integer)
9! = 40320
--
Edit bug report at http://bugs.php.net/?id=47614&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=47614&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=47614&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=47614&r=trysnapshot60
Fixed in CVS:
http://bugs.php.net/fix.php?id=47614&r=fixedcvs
Fixed in CVS and need be documented:
http://bugs.php.net/fix.php?id=47614&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=47614&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=47614&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=47614&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=47614&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=47614&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=47614&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=47614&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=47614&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=47614&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47614&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47614&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=47614&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=47614&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=47614&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=47614&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=47614&r=mysqlcfg