php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #47614 gmp_fact() parameter type not checked + documentation problem
Submitted: 2009-03-10 18:03 UTC Modified: 2009-06-26 06:31 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: postings-php-bug at hans-spath dot de Assigned:
Status: Closed Package: Documentation problem
PHP Version: 5.2.9 OS: Linux 2.6.22
Private report: No CVE-ID: None
 [2009-03-10 18:03 UTC] 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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-26 06:31 UTC] kalle@php.net
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.
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=6dff9477c978668c2a95c1bab5d9a3ca0ce7436b
Log: Fixed #47614 (gmp_fact() parameter type not checked + documentation problem)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Dec 18 08:00:02 2025 UTC