|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
19 + 2 = ?
Subscribe to this entry?

 [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: Tue Oct 04 22:05:52 2022 UTC