|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52167 gmp_pow does not accept gmp values
Submitted: 2010-06-24 09:39 UTC Modified: 2010-06-30 20:46 UTC
From: mark at hell dot ne dot jp Assigned:
Status: Not a bug Package: GNU MP related
PHP Version: 5.3.2 OS: Linux
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: mark at hell dot ne dot jp
New email:
PHP Version: OS:


 [2010-06-24 09:39 UTC] mark at hell dot ne dot jp
gmp_pow throws a "expects parameter 2 to be long" error when passed a gmp value.

Works nicely with PHP 5.2.x but not with PHP 5.3.

I am doing some maths for encryption with php which use large integers and I have 
to compute pow(a,b) with both values being large integers (~512 bits).

I'm opening this bug so we can investigate why gmp_pow() has been modified to 
only accept integers as second argument, and if there is no good reason make it 
accept gmp values again.

My guess is this change was done on the PHP_5_2 branch but not ported to PHP_5_3. 
Unfortunately svn blame couldn't fetch anything interesting to know why this 
became like this.

Test script:

Expected result:

Actual result:
Warning: gmp_pow() expects parameter 2 to be long, resource given in Command line 
code on line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-24 18:03 UTC]
-Type: Bug +Type: Feature/Change Request
 [2010-06-24 18:03 UTC]
PHP 5.3 introduced unified parameter parsing, whereas in 5.2 there were alot of places manually converting types that were not compatible.

gmp_pow()'s $exp parameter converted to an integer (long) no matter what type it had passed. In 5.3+ it was changed to require stricly to be compatible types to do type convertion.

However I do not know the exact design reason for why you cannot pass an resource and only a long, so I've changed this to be a feature request
 [2010-06-30 20:46 UTC]
-Status: Open +Status: Bogus -Type: Feature/Change Request +Type: Bug
 [2010-06-30 20:46 UTC]
In 5.2 what happens is that the resource id is converted to long. Which is not the expected behavior in many cases. i.e. it does not uses the gmp value as might looks like. 


var_dump($b); // resource(5) of type (GMP integer)
$c=gmp_pow($a,5); // equal to below


So consider the 5.3+ version as alerting about this false positive cases.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Feb 01 20:04:13 2023 UTC