#47614 [Opn->Csd]: gmp_fact() parameter type not checked + documentation problem
| From: | kalle@php.net | Date: | Fri, 26 Jun 2009 06:31:13 +0000 |
| Subject: | #47614 [Opn->Csd]: gmp_fact() parameter type not checked + documentation problem | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-2412@lists.php.net to get a copy of this message | ||
ID: 47614
Updated by: kalle@php.net
Reported By: postings-php-bug at hans-spath dot de
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: Linux 2.6.22
PHP Version: 5.2.9
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
As for the comment "gmp_fact" should check the parameter type; It does,
it checks for either for a gmp resource or else it will attempt to
convert the parameter to a long (int) without any notice.
Previous Comments:
------------------------------------------------------------------------
[2009-03-10 18:03:18] postings-php-bug at hans-spath dot de
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 this bug report at http://bugs.php.net/?id=47614&edit=1