php.net |  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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tiruchi_eral at outlook dot com
New email:
PHP Version: OS:

 

 [2020-02-08 07:50 UTC] tiruchi_eral at outlook dot com
Description:
------------
---
From manual page: https://php.net/function.str-repeat
---



Test script:
---------------
<?php

$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 ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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(https://www.hackerrank.com/challenges/repeated-string/problem), 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] requinix@php.net
-Status: Closed +Status: Not a bug -Type: Feature/Change Request +Type: Bug
 [2020-02-08 08:32 UTC] requinix@php.net
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.

<?php

$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: Thu Aug 11 18:03:36 2022 UTC