Bug #79246 [Nab]: str_repeat breaks due to limit on argument
| From: | tiruchi_eral at outlook dot com | Date: | Sat, 29 Feb 2020 17:31:23 +0000 |
| Subject: | Bug #79246 [Nab]: str_repeat breaks due to limit on argument | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225806@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79246&edit=1
ID: 79246
User updated by: tiruchi_eral at outlook dot com
Reported by: tiruchi_eral at outlook dot com
Summary: str_repeat breaks due to limit on argument
Status: Not a bug
Type: Bug
Package: *General Issues
PHP Version: 7.4.2
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2020-02-08 08:32:13] 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-08 08:19:14] 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 07:50:18] 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 ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79246&edit=1