Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gmp_mod(): Argument #1 ($num1) is not an integer string #3336

Open
sts-ryan-holton opened this issue Apr 23, 2024 · 2 comments · May be fixed by #3337
Open

gmp_mod(): Argument #1 ($num1) is not an integer string #3336

sts-ryan-holton opened this issue Apr 23, 2024 · 2 comments · May be fixed by #3337
Assignees

Comments

@sts-ryan-holton
Copy link

Description

The following code:

(new Hashids('', 7))->encode('09009956789098')

Resulted in this output:

gmp_mod(): Argument php/php-src#1 ($num1) is not an integer string

Only seems to happen when the start of the string contains a zero. Also asked at https://stackoverflow.com/questions/78371967/gmp-mod-argument-1-num1-is-not-an-integer-string-hashids-package

But I expected a correct output

usin t

PHP Version

8.3.6

Operating System

CentOS 9 stream

@sts-ryan-holton sts-ryan-holton added bug Documentation contains incorrect information Status: Needs Triage labels Apr 23, 2024
@SakiTakamachi
Copy link
Member

As per the answer on stackoverflow, a numeric string that starts with a 0 will be interpreted as an octal number.

var_dump(gmp_add('010', '010')); // 16

https://3v4l.org/seoQt

Just as binary numbers do not have the character "2", octal numbers do not have the characters "8" and "9".

Therefore, if a numeric string that is to be interpreted as octal contains an "8" or a "9", it is an invalid string.

@SakiTakamachi SakiTakamachi added Status: Invalid and removed bug Documentation contains incorrect information Status: Needs Triage labels Apr 23, 2024
@damianwadley
Copy link
Member

Making this a doc bug: the parameters say "numeric string" and then link to the strings page, which should have been a link to the numeric strings page except that "numeric string" isn't actually meant as PHP defines it but as GMP::__construct and gmp_init describe it:

The base may vary from 2 to 62. If base is 0 (default value), the actual base is determined from the leading characters: if the first two characters are 0x or 0X, hexadecimal is assumed, if the first two characters are 0b or 0B, binary is assumed, otherwise if the first character is 0, octal is assumed, otherwise decimal is assumed. For bases up to 36, case is ignored; upper-case and lower-case letters have the same value. For bases 37 to 62, upper-case letter represent the usual 10 to 35 while lower-case letter represent 36 to 61.

Applies to all the GMP functions, or at least presumably to all usages of &gmp.parameter;.

@damianwadley damianwadley transferred this issue from php/php-src Apr 23, 2024
@Girgias Girgias self-assigned this Apr 23, 2024
Girgias added a commit to Girgias/doc-en that referenced this issue Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants