Edit report at http://bugs.php.net/bug.php?id=52167&edit=1

 ID:               52167
 Updated by:       [email protected]
 Reported by:      mark at hell dot ne dot jp
 Summary:          gmp_pow does not accept gmp values
-Status:           Open
+Status:           Bogus
-Type:             Feature/Change Request
+Type:             Bug
 Package:          GNU MP related
 Operating System: Linux
 PHP Version:      5.3.2

 New Comment:

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. 



<?php



$a=gmp_init(48974);

$b=gmp_init(55);

var_dump($b); // resource(5) of type (GMP integer)

$c=gmp_pow($a,$b);

var_dump(gmp_intval($c));

$c=gmp_pow($a,5); // equal to below

var_dump(gmp_intval($c));



?>



So consider the 5.3+ version as alerting about this false positive
cases.


Previous Comments:
------------------------------------------------------------------------
[2010-06-24 18:03:56] [email protected]

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-24 09:39:19] mark at hell dot ne dot jp

Description:
------------
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:
---------------
$a=gmp_init(48974);

$b=gmp_init(55);

$c=gmp_pow($a,$b);

var_dump(gmp_intval($c));

Expected result:
----------------
int(7944261659914959072)

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

code on line 1

int(0)


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



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

Reply via email to