|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79246 str_repeat breaks due to limit on argument
Submitted: 2020-02-08 07:50 UTC Modified: 2020-02-29 17:31 UTC
From: tiruchi_eral at outlook dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.4.2 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: tiruchi_eral at outlook dot com
New email:
PHP Version: OS:


 [2020-02-08 07:50 UTC] tiruchi_eral at outlook dot com
From manual page:

Test script:

$n = 1_000_000_000_000;
$s = "abab";

print_r(repeatString($s, $n) );

Expected result:
see the string repeated $n times.

Actual result:
PHP Warning:  str_repeat() expects parameter 2 to be int, float given ...
Warning: str_repeat() expects parameter 2 to be int, float given ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-08 08:19 UTC] tiruchi_eral at outlook dot com
-Status: Open +Status: Closed
 [2020-02-08 08:19 UTC] tiruchi_eral at outlook dot com
arbitrary precision data type would solve this. like poorly named Integer in Haskell.

In my defence before I forget, among a long list of other things, I tried enabling gmp extension and using gmp_abs to create what was required, it didn't work. gmp doesn't have a alternative for str_repeat, same for bcmath.

Closing this, as I am not sure if php has something for this somewhere OOB. enabling php extensions doesn't count as OOB, and is not easy due to poor official documentation.

My goal was to complete a program quickly for solving(, without implementing orthogonal stuff.

apologies if I made any errors in reporting this issue or any other errors in general.
 [2020-02-08 08:32 UTC]
-Status: Closed +Status: Not a bug -Type: Feature/Change Request +Type: Bug
 [2020-02-08 08:32 UTC]
Do you realize that you tried to get PHP to create a string that's 4TB in size? Arbitrary precision can't help that.

Solution hint: If the desired prefix length was 4 then the answer would be 2, right? What if the prefix length was 8?
 [2020-02-29 17:31 UTC] tiruchi_eral at outlook dot com
correction to test script to make the post coherent, can't edit original post. please fix this.


$n = 1_000_000_000_000;
$s = "abab";

print_r(str_repeat($s, $n) );


Thanks for comment. I apologize for being rude, ignorant , etc. and especially for the error in test script. Again I apologize since I might be forsaking this issue for the foreseeable future. 

And not posting what I intended to due to reasons beyond my control. Sorry.
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sun Oct 02 06:05:52 2022 UTC